Skip to content

fix: auto PiP now triggers for playing videos on tab blur (#1352)#3912

Open
jiangyj545 wants to merge 1 commit into
code-charity:masterfrom
jiangyj545:fix/autopip-paused-video-1352
Open

fix: auto PiP now triggers for playing videos on tab blur (#1352)#3912
jiangyj545 wants to merge 1 commit into
code-charity:masterfrom
jiangyj545:fix/autopip-paused-video-1352

Conversation

@jiangyj545

Copy link
Copy Markdown

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:

  1. playerAutopauseWhenSwitchingTabs()pauses the video, sets played_before_blur = true
  2. playerAutoPip() — checks !video?.pausedalways 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.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant