demo · v142

PiP reason

A video plus a MediaSession action handler that opts out of auto-PiP triggered by backgrounding. Trigger PiP through the in-page button or tab-switch, then watch the log to see which details.reason value the handler received.

last received reason
document.pictureInPictureElement
null

relevant API

navigator.mediaSession.setActionHandler("enterpictureinpicture", (details) => {
  // details.reason ∈ { "auto", "userAction", "background" } in Chrome 142+
  if (details.reason === "background") return; // opt out
  video.requestPictureInPicture();
});

see also