Auto Picture-in-Picture on Tab Change

Created 4 months ago
Updated 4 months ago
Auto-enables PiP for playing videos in Chromium browsers on tab switch. Requires an initial click to unlock and exits on return.
#画中画
#视频
#自动播放
Statistics
Total Installs
65
Last 24h
+0
User Rating
-
自动在切换标签页时启用画中画模式

🎥 Auto Picture-in-Picture on Tab Change

Automatically enters Picture-in-Picture (PiP) mode for playing videos when you switch away from a tab, and exits PiP when you return.

✨ Features

  • Auto-PiP on tab switch – Triggers on both tab visibility change and window blur.
  • Auto-exit on return – Restores the video to the page when you come back.
  • Smart video selection – Picks the best candidate by visible area and playback state; prioritizes playing videos over paused ones.
  • Skips ineligible videos – Ignores hidden, zero-size, paused, ended, or disablePictureInPicture-flagged videos.
  • One-time unlock – A single click or keypress anywhere on the page (e.g. pressing Space to play) unlocks PiP for the entire session. No repeated interaction needed.
  • Lightweight – No dependencies, no permissions, no external requests.

🔧 Installation

  1. Install a userscript manager:
  2. Click the Install button.
  3. Play a video and interact with the page once (click or keypress) — then PiP activates automatically on every tab switch.

📌 Notes

  • Chromium limitation: Chromium-based browsers (Chrome, Brave, Edge, Opera) require at least one user interaction (click or keypress) before requestPictureInPicture() is permitted by the browser engine. This is a hard engine-level restriction — not a script limitation. Firefox does not have this restriction.
  • The unlock is session-wide and one-time — any normal interaction (clicking play, pressing Space, clicking a link) satisfies it invisibly.
  • Only runs in the top-level frame (window.top) to avoid conflicts on sites that use iframes.
  • Does nothing on pages with no <video> elements.

🌐 Browser Support

Browser Works Notes
Brave One interaction required
Chrome One interaction required
Edge One interaction required
Opera One interaction required
Firefox No interaction required (browser policy)

Contributing & Reporting Issues

Contact

Contact on Telegram

If you find this script useful, consider supporting its development:

Donate on Ko-fi

Thank you for your support!

Script Details
Applicable Sites
LicenseMIT