Auto Picture-in-Picture on Tab Change

Ezio Auditory
2025-02-17T16:01:49Z

Auto-enables PiP for playing videos in Chromium browsers on tab switch. Requires an initial click to unlock and exits on return.

🎥 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:

Tampermonkey

Violentmonkey

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 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

Contribute by forking the GitHub repository and submitting a pull request.

Report issues here.

Contact

Donate

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

Thank you for your support!