fix: auto PiP now triggers for playing videos on tab blur (#1352)#3912
Open
jiangyj545 wants to merge 1 commit into
Open
fix: auto PiP now triggers for playing videos on tab blur (#1352)#3912jiangyj545 wants to merge 1 commit into
jiangyj545 wants to merge 1 commit into
Conversation
…ty#1352) Root cause: playerAutopauseWhenSwitchingTabs() runs BEFORE playerAutoPip() in pageOnFocus(). The autopause handler pauses the video and sets played_before_blur=true, but then autoPiP checks !video.paused which is always false (just paused) → PiP never triggers. Fix: use this.played_before_blur flag instead of !video?.paused to check if video was playing before autopause kicked in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 PiPThe auto-PiP feature was dead code for the tab-switching scenario because the check happened after the video was already paused.
Fix
!video?.paused(real-time pause state)this.played_before_blur(pre-pause state)played_before_bluris set byplayerAutopauseWhenSwitchingTabs()before it pauses, so it correctly captures whether the user was watching a video when they switched tabs.Changes
js&css/web-accessible/www.youtube.com/player.js(1 file, +5/-1)playerAutoPip(), no behavior changes to other featuresTest Results
No new test failures introduced.
Bounty claim: This PR addresses issue #1352 (Bounty label). Requesting review.