youtube
youtube copied to clipboard
fix: auto PiP now triggers for playing videos on tab blur (#1352)
Summary
Fixes #1352 — Auto PiP only worked when video was paused, not when playing. The logic was inverted due to execution order bug.
Root Cause
In pageOnFocus(), two functions run sequentially:
playerAutopauseWhenSwitchingTabs()— pauses the video, setsplayed_before_blur = trueplayerAutoPip()— checks!video?.paused→ always false (just paused!) → never enters PiP
The auto-PiP feature was dead code for the tab-switching scenario because the check happened after the video was already paused.
Fix
| Before | After |
|---|---|
!video?.paused (real-time pause state) |
this.played_before_blur (pre-pause state) |
played_before_blur is set by playerAutopauseWhenSwitchingTabs() before it pauses, so it correctly captures whether the user was watching a video when they switched tabs.
Changes
- File:
js&css/web-accessible/www.youtube.com/player.js(1 file, +5/-1) - Only changes the condition in
playerAutoPip(), no behavior changes to other features
Test Results
Test Suites: 16 passed, 1 failed (pre-existing)
Tests: 66 passed, 3 failed (pre-existing)
No new test failures introduced.
Bounty claim: This PR addresses issue #1352 (Bounty label). Requesting review.