fix: autoplay not working when opening videos in new tabs#3651
fix: autoplay not working when opening videos in new tabs#3651quantbitrealmSimon wants to merge 1 commit intocode-charity:masterfrom
Conversation
…ty#1851) - Added player readiness check to defer autoplay decisions until player is initialized - Added detection for new tab scenarios using document.visibilityState and performance timing - Allow autoplay for new tabs unless explicitly disabled by user - Prevents race condition where autoplayDisable runs before player element is available Fixes code-charity#1851
|
|
||
| if (isNewTab && !this.storage.player_autoplay_disable) { | ||
| // Allow autoplay for new tabs unless explicitly disabled | ||
| document.dispatchEvent(new CustomEvent('it-play')); |
There was a problem hiding this comment.
this event is to inform other features which might pause it
Lines 250 to 255 in 0534d71
|
hi! @quantbitrealmSimon |
|
Hi @ImprovedTube, thank you for the review and feedback. You're right to question this - I should have been more thorough. Looking at your suggested approach, I can see that my implementation has issues. The I'll revise this PR to use your suggested pattern: if (!player && !videoElement.closest('.html5-video-player')) {
// Player not ready yet, defer check
setTimeout(function () {
ImprovedTube.autoplayDisable(videoElement);
}, 100);
return;
}This is cleaner and properly defers until the player is initialized. I'll update the PR shortly with the corrected implementation. Apologies for the initial submission - I appreciate you taking the time to provide constructive feedback. |
Per maintainer feedback on PR code-charity#3651: - Removed the problematic isNewTab detection and it-play event dispatch - Kept the player readiness check that defers autoplay until player is initialized - This is the minimal fix suggested by @ImprovedTube
|
Update: I've pushed the fix to my fork at The changes:
The PR might need to be updated to point to the new fork since the original |
|
thank you @realmpastai-web
|
d4783a9 to
0403173
Compare
This PR fixes the autoplay issue when opening YouTube videos in new tabs (#1851).
Problem
When users opened videos in new tabs, the autoplay feature would not work correctly.
Solution
Fixes #1851
/claim