Skip to content

Commit

Permalink
fix playerAutopauseWhenSwitchingTabs when minimizing browser
Browse files Browse the repository at this point in the history
Chrome sends two blur events and breaks restoring play
  • Loading branch information
raszpl authored Jun 16, 2024
1 parent 85bf124 commit 670e746
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ ImprovedTube.forcedPlayVideoFromTheBeginning = function () {
AUTOPAUSE WHEN SWITCHING TABS
------------------------------------------------------------------------------*/
ImprovedTube.playerAutopauseWhenSwitchingTabs = function () {
var player = ImprovedTube.elements.player;
const player = this.elements.player;

if (this.storage.player_autopause_when_switching_tabs === true && player) {
if (this.focus === false) {
this.played_before_blur = player.getPlayerState() === 1;

player.pauseVideo();
} else if (this.focus === true && this.played_before_blur === true) {
if (this.storage.player_autopause_when_switching_tabs && player) {
if (this.focus && this.played_before_blur && this.elements.video.paused) {
player.playVideo();
} else {
this.played_before_blur = !this.elements.video.paused;
if (!this.elements.video.paused) {
player.pauseVideo();
}
}
}
};
Expand Down

0 comments on commit 670e746

Please sign in to comment.