youtube icon indicating copy to clipboard operation
youtube copied to clipboard

autoplay problem

Open nairblyL opened this issue 2 years ago • 42 comments

Bug Report:

BUG: Videos auto play even when the option is turned off if the window is in focus. ⚬ HOW: Open a video in the current window or refresh a tab with a paused video. Expected behaviour: The video auto pauses. Actual behaviour: The video auto plays.

⚬ If a YouTube change started the bug, please copy the DOM you get (especially if the bug doesn't happen when you log out or on another computer) ⚬ Or did our last update start the bug? ⚬ ImprovedTube Version: 4.700

1. Thanks for coming & caring! Before submitting, please check if the issue has already been reported ever. With GitHub's issue search (use this link) (else removing "is:issue is:open" from the standard search) ( - If it was posted before, you can answer/react there to give it your voice and move it up in the lists) ( - If the status is "closed" (=fixed) recently, then Web Stores can be updated soon - if it was closed month or years ago, then it might reappeared & must be fixed again.)

2. To give us a chance to solve the bug: Can you ...?: - ..deactivate other extensions running on YouTube? (or use an incognito window after activating this extension to run there / chrome://extensions details chrome://extensions/?id=bnomihfieiccainjcjblhegjgglakjdd ) - ..open the Browser-console, with the F12-Key, before/when the error occures? (then hopefully you'll see an error message in the console). - ...copy the YouTube-DOM shown above the console (F12) in case YouTube is giving you a new verson. You can copying the root element <html> in the top after the bug happened: (FireFox:) - There are 2-3 different versions depending if you open a new window or clicked a link on youtube

⚬ Browser: Chrome 121.0.6167.185
⚬ Settings:

⚬ OS: Win10 ⚬ Device:

nairblyL avatar Feb 23 '24 23:02 nairblyL

hi @nairblyL since when?

ImprovedTube avatar Feb 24 '24 03:02 ImprovedTube

hi @nairblyL since when?

As far as I can tell since the fix for the looping issue.

nairblyL avatar Feb 24 '24 03:02 nairblyL

since ~couple of weeks. Its really weird. If I open YT video in new window by pasting url manually Autoplay=off works If I now refresh thit page Autoplay=off still works If I open another YT clip in the background from YT page it will not play until switching focus to that Tab. after switching focus it autoplays ignoring Autoplay=off If I now refresh this tab it still autoplays. Gets better - if I open devtools on this broken Tab it magically starts working after refresh

sure enough https://github.com/code-charity/youtube/blob/b412f2dde393dc18e9a3e415ef1e74815ba14984/js%26css/web-accessible/www.youtube.com/player.js#L18 I can see multiple "autoplay:off - should we pause here again?" in console log, this is to blame. This broke it https://github.com/code-charity/youtube/commit/dc00a7e92701c83e2722c2346275a3380cc61d11 "fixes & tidy" is not a great commit message to put it mildly :) cant see what issue this is supposed to fix

raszpl avatar Mar 04 '24 07:03 raszpl

broken on latest firefox release as well

spice42 avatar Mar 17 '24 10:03 spice42

and its broken completely now after reverse to broken version https://github.com/code-charity/youtube/issues/2105#issuecomment-2003966180

raszpl avatar Mar 18 '24 13:03 raszpl

@ImprovedTube what was the purpose of autoplayDeniedOnce introduced in https://github.com/code-charity/youtube/commit/dc00a7e92701c83e2722c2346275a3380cc61d11 this breaks "disable Autoplay" For me the main reason for using ImproveTube is disabling autoplay :(

raszpl avatar Mar 19 '24 15:03 raszpl

The log is friendly: It points out probably unnecessary extra runs. The commit message missed to mention https://github.com/code-charity/youtube/issues/1809#issuecomment-1922634933. (if you find that undoing the commit helps @raszpl, we can just make sure that it won't pause long after the page-load or after the user clicks play or that https://github.com/code-charity/youtube/issues/1809#issuecomment-1922634933 isn't related.) Else, to solve the bug you can check while/if it happens, if our autoplay-off function runs at all. (It might makes 0 attempts then.) The feature once designed to quit onkeydown & onmousedown: https://github.com/search?q=repo%3Acode-charity%2Fyoutube%20ignore_autoplay_off&type=code
( Btw, to make sure: did the bug pause on March 17? @nairblyL @redcat42 @grndkntrl & did it ever happen before Feb22 since when? ) Thanks for caring!

One way to semi fix this might be to detect this happening and re-initialize autoplay/volume and whatever else

https://github.com/code-charity/youtube/issues/1809#issuecomment-1876116973

Similar might happens or have increased since youtube's update including adblocker alerts (October 18, 2023) which changed a lot. Yet i dont know. (Reporters of issue 1851 might also be new users.)


You'd probably enjoy at the top of our To-Do-List to simply allow everyone to enable/disable all of youtube's experiment flags (up to 800?) - (and crowdsourcing what they even mean): https://github.com/code-charity/youtube/issues/1851#issuecomment-1836081643
*'at the top' besides these days i / we also should test Manifest v3 (converting some lines and keeping alive the background worker)

commit message

...while most maintainers work alone most of the time..(, some commit messages might only express justifiable confidence that it might be uncritical enough or include noise, not rewarding enough to go back anytime soon just to document each bit.) Yet we are lucky! Raszpl is back! (And luckily we have several users too already)

All of which should lead to thinking of more team-work and better collaborative tools!(?) But many maintainers seem to "want" to stay alone 😲.
While in our little niche each maintainer's "sisyphus-torture" alone doesn't sufficiently care for the user. - So instead every developer in average is frustrating many users 🤔 (possibly without noticing? - while the user-counts are replaced while younger generations arrive). Discussed here: https://github.com/code-charity/youtube/discussions/1881#discussioncomment-7820498. Many also seem to believe in ownership. (Whats farther from commercial ownership than our niche yet? One might think, one should believe in ownership, because other people do?). Yet that's contrary so far, while most of our niche is volunteering, dependent on YouTube and comparably modest (while team-work will first raise efficiency and optionally even commercial self-sustainability too.)

ImprovedTube avatar Mar 21 '24 10:03 ImprovedTube

my comment moved from https://github.com/code-charity/youtube/pull/2109

1 We have a feature called "autoplay" 'player_autoplay' while it should be called "Disable Autoplay", https://github.com/code-charity/youtube/pull/2110 addresses this

2 ignore_autoplay_off is confusing, renaming to user_interacted better reflects its role. User clicking on a page = user interacting = need to pass HTMLMediaElement.prototype.play no matter other settings

3: https://github.com/code-charity/youtube/blob/cac7962b8d566b4526b7001cc07c2b206b438f15/js%26css/web-accessible/init.js#L98

https://github.com/code-charity/youtube/blob/cac7962b8d566b4526b7001cc07c2b206b438f15/js%26css/web-accessible/functions.js#L325 both are too late, this is the reason for up to 1 second play even with autoplay disabled, something https://github.com/code-charity/youtube/commit/39ada0f68cbb77195982531a4d72ff05e9e96e16 failed to fix This needs to be on top of init.js just like the 30fps and codec overrides so it catches before YT starts interacting with the page.

raszpl avatar Mar 22 '24 07:03 raszpl

hi! 🎉 yes, AutoplayOFF should be fast (or notice if the user already clicked the player, play button, or a shortcut to play. And i think someone started considering more user interaction, when there once was some unwanted/unclear pausing during youtube navigation.) (Different story you might remember: #1508)

Pseudo-code :

PlayOrPause? () {

is this tab active(Case A) or in the background?(B) 
AND is this video a "next video"?[1.AI suggestion 2.my playlist 3. public playlist] 
( OR a new page-load[4.after restoring a browser session|clicking[a Link?
  [5. external|6.internal|7."related video"]|8.bookmark] | 9.embedded player?10.still invisible below the fold?)
AND was this just first activated/fully rendered after being opened in the background?(Case C)
) 
AND is it music or another specific genre? AND is this from from my subscriptions or not?

} So there easily is an Array with many possibilities (3*10-3)*3*2), many of which could be smart/efficient. 🤔(#1081).

While case B or C might need developer attention and since v4.0 tab status code in background.js was reduced to quickly test Manifest v3. And the same could can equally be considered when deciding other parameters such as volume or speed.


Long-term structure/vision for our UI:

  1. my content & discovery logic

  2. my~?setup:
    a) (Web-)Video Features (+specific Youtube Tweaking + Youtube's Experiment Flags , those added by the user) ). b) Youtube: Cleaning/Trashbin (Up to 100s (including disabled Youtube's Experiment Flags) Ideally needed decreasingly often.) c) Youtube Minimap/Layout (more sections, maybe Drag&drop for Sizes, Positions & paint bucket for Colors)

( https://github.com/code-charity/youtube/discussions/848#discussioncomment-588359, https://github.com/code-charity/youtube/issues/890#issuecomment-1034264001 )

while extra exceptions/conditions like video genre could be set for many features on right click. and shortcuts or buttons to toggle any experiment flag or anything could be setup with right click too.


#2110 user_interacted

👍 good (...#2111) and while avoiding negation, the word: Disable could also stay shortened somehow. (Can be avoided in code & translations[often enough to translate the word 'disable' alone instead as an option name instead of a new string of two words] )
And ultimately, unlike for the early extension users, new users don't need to care what are Youtube's-defaults but just what they need/want. ( And our UI needs not 45 negation-words/language strings, but maybe just one for all. Since our Default:"true"[Autoplay UpNext Loudness Normalization 60FPS Crop-Chaptertitles] are just YouTube features, that users might want to subtract from YouTube [and only keep only in the "trashbin"]. So in our UI we can keep showing them enabled a but also just visually marked/ordered as Youtube defaults, that the user might want to decide about all in a row (unless 😀 in future we allow the same auto play on off button for all web video including facebook.com/watch, etc.) ) - Of course on the contrary "disable autoplay" is of course a more common phrase than "enable autoplay" (just like for HDR and SDR #1460 (highlight) ) - At least generally, this is the way as shortcuts demonstrates: We have to show YouTube's defaults to make it convenient. To make the whole combined thing better. Same will be, when we offer a view on the list of all Youtube experiment flags. While no fixed defaults exist and vary between youtube accounts and several of them include the word autoplay. So we boost our Features anytime and just need to crowdsource or measure the meaning of the flags and order by relevance or by current goal of the user: cleaning/minimalism OR trying new features. While each feature and each experiment can always appear on both lists, just often at a whole different ranking (and
depending each user's previous normality, as defined by what YouTube gave or what was set with us)

ImprovedTube avatar Mar 22 '24 14:03 ImprovedTube

#2110

(Still need to check if settings are false or true #1685 #2085)

https://palantir.github.io/tslint/rules/no-boolean-literal-compare/ https://typescript-eslint.io/rules/no-unnecessary-boolean-literal-compare/ https://rules.sonarsource.com/java/RSPEC-1125/ https://www.c-sharpcorner.com/article/common-code-smell-mistakes-in-c-sharp-part-1/

And ultimately, unlike for the early extension users, new users don't need to care what are Youtube's-defaults but just what they need/want.

This is how you end up with people blaming extension for Autoplay not working. Calling it what it is clears all confusion. "Force Autoplay Off" is a good start, "Disable automatic Video playback" is another one.

( And our UI needs not 45 negation-words/language strings, but maybe just one for all. Since our Default:"true"[Autoplay UpNext Loudness Normalization 60FPS HDR Crop-Chaptertitles] are just YouTube features, that users might want to subtract from YouTube [and only keep only in the "trashbin"]. So in our UI we can keep showing them enabled a but also just visually marked/ordered as Youtube defaults,

sounds good on paper until one of those YT features doesnt work for some reason and user blames extension because "its clearly ON in the extension ergo extension doesnt work" :)

raszpl avatar Mar 23 '24 01:03 raszpl

palantir.github.io/tslint/rules/no-boolean-literal-compare

😆sorry @raszpl (repeated this with my head off, vaguely remembering https://github.com/code-charity/youtube/commit/3cd0c66143c14494d715bd8b38fa3f4001c6d3d7 )

user blames extension because "its clearly ON in the extension ergo extension doesnt work" :)

Yeah! Not decided, just for the debate: Could have a strong headline like "Disable Youtube features/defaults?" Red colored list, with check-boxes, while unchecking makes the elements greyed out. (without our red glowing toggles) (+not sure how many bad reviews come from this actually - Could add a tooltip/link to browser's autoplay settings.)

ImprovedTube avatar Mar 23 '24 19:03 ImprovedTube

😆sorry @raszpl (repeated this with my head off, vaguely remembering 3cd0c66 )

This is a great example! https://github.com/code-charity/youtube/commit/3cd0c66143c14494d715bd8b38fa3f4001c6d3d7 We need player_60fps === false here because we were relying on Default ON - every user having player_60fps already set to true by default.

https://github.com/code-charity/youtube/issues/1689 came about because of this backwards naming. Calling it "Allow 60fps" suggests we are doing something special to 60fps videos which is not true. Extension can only block 60fps, it cant really "allow" anything. If this was called "Force 30fps limit" that bug would never have happened :) Imo naming options in a way suggesting they are doing something while this ON state results in Extension not doing anything is a bad idea.

raszpl avatar Mar 25 '24 05:03 raszpl

Thank you for your email

On Sat, 24 Feb, 2024, 4:38 AM nairblyL, @.***> wrote:

Bug Report:

BUG: Videos auto play even when the option is turned off if the window is in focus. ⚬ HOW: Open a video in the current window or refresh a tab with a paused video. Expected behaviour: The video auto pauses. Actual behaviour: The video auto plays.

⚬ If a YouTube change started the bug, please copy the DOM you get (especially if the bug doesn't happen when you log out or on another computer) ⚬ Or did our last update start the bug? ⚬ ImprovedTube Version: 4.700

1. Thanks for coming & caring! Before submitting, please check if the issue has already been reported ever. With GitHub's issue search (use this link) https://github.com/ImprovedTube/ImprovedTube/issues?q= (else removing "is:issue is:open" from the standard search) ( - If it was posted before, you can answer/react there to give it your voice and move it up in the lists) ( - If the status is "closed" (=fixed) recently, then Web Stores can be updated soon - if it was closed month or years ago, then it might reappeared & must be fixed again.)

2. To give us a chance to solve the bug: Can you ...?:

⚬ Browser: Chrome 121.0.6167.185 ⚬ Settings:

⚬ OS: Win10 ⚬ Device:

— Reply to this email directly, view it on GitHub https://github.com/code-charity/youtube/issues/2042, or unsubscribe https://github.com/notifications/unsubscribe-auth/A45NS753UQ3KUQIINMEJW6DYVEONJAVCNFSM6AAAAABDXO6UTKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGE2TCOJTGMZTCMY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Tithi49 avatar Mar 25 '24 05:03 Tithi49

exactly @raszpl. 1.) All can be false by default (

[Autoplay UpNext Loudness Normalization 60FPS Crop-Chaptertitles] )

2.) UI: Negation("trashbin") is category more than a feature.

Just re-wrote #1685

ImprovedTube avatar Mar 25 '24 19:03 ImprovedTube

the myth goes on disable autoplay

ImprovedTube avatar Mar 26 '24 10:03 ImprovedTube

Ver 8.420

Disabled all extensions, and surprisingly, YT videos autoplayed. Enabled just the IT extension, and I had to manually play the videos.

sonal-g123 avatar Mar 31 '24 17:03 sonal-g123

hi! @sonal-g123 did you switch off autoplay with the extension? (our feature is on when the switch if off)

ImprovedTube avatar Mar 31 '24 22:03 ImprovedTube

Here are my settings https://imgur.com/a/13HgKtj To be clear, I am talking about autoplay on the videos I click, and not for the videos in YT's playlists.

I just uninstalled and reinstalled your main (4.823) and Test extensions. Even with no feature on (I checked the active features setting), my videos did not play on their own. As soon as I uninstalled these apps, the autoplay began to work. I also manually tried to switch your extension's autoplay feature on and off, and tested both. For both, the videos did not play automatically. I use Chrome, if that's helpful.

sonal-g123 avatar Apr 01 '24 02:04 sonal-g123

Bumping this up in case it was overlooked

sonal-g123 avatar Apr 03 '24 03:04 sonal-g123

hi @sonal-g123, im not getting such error, please check the browser console.

ImprovedTube avatar Apr 03 '24 04:04 ImprovedTube

https://github.com/code-charity/youtube/blob/b412f2dde393dc18e9a3e415ef1e74815ba14984/js%26css/web-accessible/www.youtube.com/player.js#L18

I can see multiple "autoplay:off - should we pause here again?" in console log, this is to blame. This broke it dc00a7e "fixes & tidy" is not a great commit message to put it mildly :) cant see what issue this is supposed to fix

I finally know! I disabled this whole autoplayDeniedOnce to find out and finally triggered it. I just experienced a video that kept auto pausing forcing me to keep clicking right in the middle of Video window 7 times in a row, finally let me watch after 8th click. I have additional logging sprinkled all over the place:

14:49:30.805 player.js:26 Pause in settimeout 14:49:31.044 player.js:26 Pause in settimeout 14:49:31.047 player.js:26 Pause in settimeout 14:49:31.049 player.js:26 Pause in settimeout 14:49:32.186 player.js:26 Pause in settimeout 14:49:33.455 player.js:26 Pause in settimeout 14:49:35.485 player.js:26 Pause in settimeout

so I can see it was pausing in https://github.com/code-charity/youtube/blob/04a604b4b53213d98917ab44448a30024200af99/js%26css/web-accessible/www.youtube.com/player.js#L19

Problem lies here: https://github.com/code-charity/youtube/blob/04a604b4b53213d98917ab44448a30024200af99/js%26css/web-accessible/functions.js#L446-L461

somehow this elaborate list of conditions sometimes very rarely prevents ImprovedTube.user_interacted = true; when user clicks Play on newly opened page. Result was [Bug: Extension seems to keep pausing the player. Needs immediate action] https://github.com/code-charity/youtube/issues/1387 followed by [Bug: Extension still keeps pausing the player. Not solved.] https://github.com/code-charity/youtube/issues/1592 so my guess is autoplayDeniedOnce was added to prevent repeated pauses, but source of the problem is in onmousedown handler. Looking at other html5-stop-autoplay extensions there should be no conditions in the handler - user clicking anywhere should be enough signal to disable pausing. our keydown handler doesnt bother with any comparisons and just works https://github.com/code-charity/youtube/blob/04a604b4b53213d98917ab44448a30024200af99/js%26css/web-accessible/functions.js#L438-L441

raszpl avatar Apr 10 '24 12:04 raszpl

and there it is!

16:34:31.029 functions.js:448 mousedown listener
16:34:31.029 functions.js:450 mousedown in player
16:34:31.110 player.js:26 Pause in settimeout

my instrumented mousedown handler:

ImprovedTube.onmousedown = function (event) {
	window.addEventListener('mousedown', function (event) {
		console.log('mousedown listener');
		if (ImprovedTube.elements.player && ImprovedTube.elements.player.classList.contains('ad-showing') === false) {
			console.log('mousedown in player');
			var path = event.composedPath();

			for (var i = 0, l = path.length; i < l; i++) {
				if (path[i].className
					&& path[i].className.indexOf
					&& (path[i].className.indexOf('html5-main-video') !== -1
						|| path[i].className.indexOf('ytp-play-button') !== -1)) {
					console.log('mousedown user_interacted');
					ImprovedTube.user_interacted = true;
				}
			}
		}
	}, true);
};

so when I just clicked in the middle of Video window onmousedown handler triggered and managed to log 'mousedown listener' 'mousedown in player' but not 'mousedown user_interacted' and video was still paused. Video is question was vertical, so doesnt cover whole video window. 'html5-main-video' only covers the video bit, not whole video window. YT starts playing when clicking anywhere in Video window, doesnt restrict to just 'html5-main-video' part.

Seems the easiest fix will be removing all the junk from onmousedown handler.

raszpl avatar Apr 10 '24 14:04 raszpl

Great! @raszpl
i'm setting a 800ms limit & we could add more alternatives to the regex: https://github.com/code-charity/youtube/commit/e56ddb2ef2964d3e2c58f248b8df5dcc9268c509?diff=unified&w=1

At least 1 in the 3 reports we got isn't a vertical video (Firefox):

I'm using Firefox, and with version 4.615, I can confirm that with the "Autoplay" setting off, the video will not start https://github.com/code-charity/youtube/assets/55325485/5f8c6ea5-8d41-465b-b817-d1efabda65d1

( https://github.com/code-charity/youtube/issues/1809#issuecomment-1951532778 )

For Brave & Opera GX Did repeated pausing (autoplay off, #1809) only happen in vertical videos to one of you guys? @stuart-brown @JLewis1309 )

ImprovedTube avatar May 06 '24 12:05 ImprovedTube

hi! @nairblyL @redcat42 can you tell if this (#2042) still happens with the latest.zip?

ImprovedTube avatar May 06 '24 19:05 ImprovedTube

Great! @raszpl i'm setting a 800ms limit & we could add more alternatives to the regex: e56ddb2?diff=unified&w=1

At least 1 in the 3 reports we got isn't a vertical video (Firefox):

I'm using Firefox, and with version 4.615, I can confirm that with the "Autoplay" setting off, the video will not start https://github.com/code-charity/youtube/assets/55325485/5f8c6ea5-8d41-465b-b817-d1efabda65d1

( #1809 (comment) )

For Brave & Opera GX Did repeated pausing (autoplay off, #1809) only happen in vertical videos to one of you guys? @stuart-brown @JLewis1309 )

The Pausing happened in every video, at some point i disabled the extension again (Dont remember why) and i just today reenabled it so will see if any of the issues still show up for me EDIT: Using Version 4.1007 on Vivaldi Browser, it was working just fine with the "Player > Force Autoplay Off" option enabled but just now it randomly stopped working and the videos start paused and trying to play them just doesnt work but if i disable the extension or disable Force Autoplay off and refresh it works ¯_(ツ)_/¯

xSnufflesx avatar Jun 27 '24 08:06 xSnufflesx

working just fine with the "Player > Force Autoplay Off" option enabled but just now it randomly stopped working and the videos start paused

wait, "Force Autoplay Off" option enabled is supposed to make all videos start paused

and trying to play them just doesnt work

need to see errors in console

raszpl avatar Jun 29 '24 05:06 raszpl

i might of worded it wrong, when its working properly Force Autoplay Off Enabled will make videos start paused and then when i unpause they play normally When its not working the videos start paused but when trying to unpause they wont unpause and the video just stays permanently paused until i disable the option or the extension and refresh the page. Just reenabled Force Autoplay Off and it seems to be working again for now so i have no clue whats causing it to work fine sometimes then other times it will just stop working. It seems to come and go

xSnufflesx avatar Jun 29 '24 22:06 xSnufflesx

Next time this happen open console and copy all the errors please. Something is most likely crashing.

raszpl avatar Jun 30 '24 00:06 raszpl

Hopefully this helps https://i.imgur.com/poojoko.png https://i.imgur.com/4lyTQeH.png https://i.imgur.com/99kezKm.png https://i.imgur.com/rKrd3X9.png

Also for what its worth seems i dont have to refresh the page to get the bug to happen or go away, i enable Force Autoplay off and the video wont play when i try to unpause it, i disable the setting and i can play the video fine. all without restarting the page

xSnufflesx avatar Jun 30 '24 10:06 xSnufflesx

Nothing is crashing, but there is 10 video Pause events in the first screenshot. Having recently looked at shortcut code its possible it is overriding ImprovedTube.onkeydown thus not running ImprovedTube.user_interacted = true; thus ImprovedTube.autoplayDisable : if (player && !this.user_interacted passing every time because extension doesnt notice you clicked a button and will prevent every click.

While Play is not working and you are in console run ImprovedTube.user_interacted and check if it isnt false by any chance

also how are you trying to play the video? with a keyboard (for example 'space') or by clicking inside the Video area with a mouse? or touch pad?

raszpl avatar Jun 30 '24 12:06 raszpl