The enterpictureinpicture event is fired when the HTMLVideoElement enters picture-in-picture mode successfully.
This event is not cancelable and does not bubble.
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("enterpictureinpicture", (event) => { })
onenterpictureinpicture = (event) => { }A PictureInPictureEvent. Inherits from Event.
These examples add an event listener for the HTMLVideoElement's enterpictureinpicture event, then post a message when that event handler has reacted to the event firing.
Using addEventListener():
const video = document.querySelector("#video");
const button = document.querySelector("#button");
function onEnterPip() {
console.log("Picture-in-Picture mode activated!");
}
video.addEventListener("enterpictureinpicture", onEnterPip);
button.onclick = () => {
video.requestPictureInPicture();
};Using the onenterpictureinpicture event handler property:
const video = document.querySelector("#video");
const button = document.querySelector("#button");
function onEnterPip() {
console.log("Picture-in-Picture mode activated!");
}
video.onenterpictureinpicture = onEnterPip;
button.onclick = () => {
video.requestPictureInPicture();
};