code-charity / youtube

[top~1 open YouTube & Video browser-extension] - Enrich your experience & choice! 🧰180+ options & clever features 📌set+forget📌Longest-standing(been tough). Please join🧩us👨‍👩‍👧‍👧 ..⋮ {playback|content discovery|player|extra buttons|distractions|related videos|shorts|ads|quality|codec|full tab|full screen}
http://improvedtube.com
Other
3.54k stars 542 forks source link

Autplay not working. Ver 4.820 #2137

Open sonal-g123 opened 7 months ago

sonal-g123 commented 7 months ago

By autoplay, I mean the video I click on, not the videos lined up in my playlist. This play button has not been working for months now and I have to manually click on the "play" button on the 20+ videos I watch daily

Not sure if this is a bug or if it's bc of YT's changed algorithm, but is it possible to take a look at it?

Thank you <3

raszpl commented 7 months ago

Are you sure this is ImproveTube. If anything ImproveTube has trouble pausing videos in the first place. Try temporarily disabling it and browsing YT for few hours.

sonal-g123 commented 7 months ago

Are you sure this is ImproveTube. If anything ImproveTube has trouble pausing videos in the first place. Try temporarily disabling it and browsing YT for few hours.

I did. I uninstalled all extensions except IT and nothing changed. I uninstalled IT and kept all my other extensions, and YT videos started auto playing. I tried it with both their main and Beta extensions - the result was the same. I finally decided to permanently remove this extension from my browser. It's wonderful, but I really loathe having to manually click play on 20+ videos on a daily basis.

raszpl commented 7 months ago

Did you switch Autoplay in options of ImproveTube? The only way for ImproveTube to do anything to video playback is for you to switch Autoplay off first.

sonal-g123 commented 7 months ago

I tried both on and off for autoplay. Didn't work for either

On Monday, April 8, 2024, Rasz_pl @.***> wrote:

Did you switch Autoplay in options of ImproveTube? The only way for ImproveTube to do anything to video playback is for you to switch Autoplay off first.

— Reply to this email directly, view it on GitHub https://github.com/code-charity/youtube/issues/2137#issuecomment-2042244191, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQLZPK3HQQL4OTP5MDEULLTY4JNCRAVCNFSM6AAAAABFQSNFC2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBSGI2DIMJZGE . You are receiving this because you authored the thread.Message ID: @.***>

MRiCEQB commented 7 months ago

I have the same issue - or a similar one. Whenever I go on YouTube and find several videos I want to watch, I use the middle mouse button to open them in individual tabs. In the past they started to autoplay, once I selected the desired tab - now they are always on pause. This doesn't happen when I open a video right away (left mouse button).

I first suspected my uBlock Origin extension but the error indeed only goes away, once I disable ImproveTube. If you require any logs or something, please let me know.

sonal-g123 commented 7 months ago

Funny. I reinstalled the app and removed Ublock and noticed that videos in the same tab will autoplay, but when opened in a new tab, they don't play One of the devs said this isn't an issue from their end, so I'm not sure what more can be done at this point

On Fri, Apr 19, 2024 at 5:31 PM MRiCEQB @.***> wrote:

I have the same issue - or a similar one. Whenever I go on YouTube and find several videos I want to watch, I use the middle mouse button to open them in individual tabs. In the past they started to autoplay, once I selected the desired tab - now they are always on pause. This doesn't happen when I open a video right away (left mouse button).

I first suspected my uBlock Origin extension but the error indeed only goes away, once I disable ImproveTube. If you require any logs or something, please let me know.

— Reply to this email directly, view it on GitHub https://github.com/code-charity/youtube/issues/2137#issuecomment-2066424395, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQLZPK3AIXVXTSFTBUFQG4TY6EBRDAVCNFSM6AAAAABFQSNFC2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRWGQZDIMZZGU . You are receiving this because you authored the thread.Message ID: @.***>

MRiCEQB commented 7 months ago

When you now disable ImprovedTube, does it autoplay in the next tab?

sonal-g123 commented 7 months ago

yup. seems like the default youtube setting.

On Thu, Apr 25, 2024 at 10:39 AM MRiCEQB @.***> wrote:

When you now disable ImprovedTube, does it autoplay in the next tab?

— Reply to this email directly, view it on GitHub https://github.com/code-charity/youtube/issues/2137#issuecomment-2076366382, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQLZPK25XRE4FPBERAFM4HLY7CFYVAVCNFSM6AAAAABFQSNFC2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZWGM3DMMZYGI . You are receiving this because you authored the thread.Message ID: @.***>

MRiCEQB commented 7 months ago

So (at least to my understanding) ImprovedTube does something, that causes this behavior.

raszpl commented 7 months ago

Default youtube setting is ALL videos Pause when opened in background tab, but start autoplaying when you click on that tab and make it active/visible.

MRiCEQB commented 7 months ago

Default youtube setting is ALL videos Pause when opened in background tab, but start autoplaying when you click on that tab and make it active/visible.

Correct and this behavior does not work for us, as long as ImprovedTube is active. Once we disable ImprovedTube, it works as intended.

ImprovedTube commented 7 months ago

hi, please open the browser console when (before or after) the issue happens to copy any errors or log message from us (not those from Youtube or third parities) @sonal-g123 @MRiCEQB
thanks!

MRiCEQB commented 7 months ago

This is a bit tricky to catch, because the console needs to be activated for each tab (as fas as i can tell). So opening a new tab -> clicking it -> hitting F12, might not catch the error in time or any log at all. Here I have one entry from ImrovedTube, but that also shows up, when I open a video directly in the same window (means not in a new tab).

www.youtube.com-1714134095880.log

raszpl commented 7 months ago

console doesnt need to be open prior to log errors. there are no errors in your log file what browser? can you try disabling all other extensions but improvetube?

MRiCEQB commented 7 months ago

I'm using Chrome. Disabled everything except ImprovedTube and the error still remains. Once ImprovedTube is disabled, the video start to play as expected, once I switch to their tab.

ImprovedTube commented 7 months ago

thank you! @MRiCEQB
please type in the browser console yt.config_.EXPERIMENT_FLAGS (enter) rightclick on the result: copy object

@sonal-g123 @jerrk @codeClimberNT @sidonly @drnopt killthe3vil @Evoden1 @xeophyte


( then we can compare further which might be the reason https://docs.google.com/spreadsheets/d/1GidvMduxTl6jXpDCKj-sOPg8KSqDfCYO2OlCdBADaSI/edit#gid=0 )

https://github.com/code-charity/youtube/issues/1851#issuecomment-1836081643


March

without IYT extension also doesn't work. https://github.com/code-charity/youtube/issues/1809#issuecomment-2009516001

December

It just started to work for me https://github.com/code-charity/youtube/issues/1851#issuecomment-1847059103

December

And today the autoplay stopped working again ;]

2136 (with @Jerrk's ctrl+u.txt already )

1867 #2012

Jerrk commented 7 months ago

I did the result twice, once when the problem occurs and then another time after clearing cookies and the problem is gone.

I ran a diff check on both of them and there is no difference

problem.txt

CodeClimberNT commented 7 months ago

Just as an FYI I had to format and reinstall my Windows 11 and most of the problem were fixed (not all of it!), anyway those are my flags: experimental-flags.json. One thing I think I need to mention, before formatting my computer was very slow and found similar issue using another extension to change YouTube behavior to be unreliable with respect of another computer of mine that never had issue whatsoever (lot of RAM, very powerful CPU). I don't know if actually using YouTube for a long time make you more susceptible to have those flags changed, or maybe is some sort of memory saving of the browser that in some particular condition (previously I had a lot of memory swap used and still am, but now it's very limited) will limit the functionality of the extension. I found the latter very difficult to believe but better give as much information as possible. As others have noted, clearing the browser cookie (or reinstalling the OS in my case) will fix a lot of issues.

xeophyte commented 7 months ago

image


edit: hi @xeophyte! Can type console prompts just below, after the ">"

Evoden1 commented 7 months ago

https://gist.github.com/Evoden1/747254eb676cf5da1a4f8044dbe64757

the yt.config_.EXPERIMENT_FLAGS result

sonal-g123 commented 7 months ago

I'm glad other people spoke up about this issue. Previously, I was the only one and Admin told me that they weren't facing thay issue from their end, and that was that.

On Saturday, April 27, 2024, Evoden1 @.***> wrote:

https://gist.github.com/Evoden1/747254eb676cf5da1a4f8044dbe64757

the yt.config_.EXPERIMENT_FLAGS result

— Reply to this email directly, view it on GitHub https://github.com/code-charity/youtube/issues/2137#issuecomment-2080163545, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQLZPK3X5ATWAARK67SILCDY7LD3JAVCNFSM6AAAAABFQSNFC2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBQGE3DGNJUGU . You are receiving this because you were mentioned.Message ID: @.***>

raszpl commented 7 months ago

Ok, since we have couple of you here able to trigger this reliably. Experiment:


edit: hi @raszpl! applies with unzipped "developer mode" installations. If it was installed from the webstore, modifying and reloading an extension will be noticed as corrupted and won't load.

xeophyte commented 6 months ago

I deleted setTimeout(function () { video.pauseVideo(); }); and restarted browser and extension and still have no autoplay.

raszpl commented 6 months ago

just to make sure it was correct file, can you also paste full location of /js&css/web-accessible/player.js you were editing? and copy result of JSON.stringify(ImprovedTube.storage) command from console. the only other spot where extension tries to pause is with enabled playerAutopauseWhenSwitchingTabs and pause message https://github.com/search?q=repo%3Acode-charity%2Fyoutube%20pauseVideo&type=code, but those dont fire on their own

xeophyte commented 6 months ago

\AppData\Local\Vivaldi\User Data\Default\Extensions\bnomihfieiccainjcjblhegjgglakjdd\4.826_0\js&css\web-accessible\www.youtube.com\player.js

and copy result of JSON.stringify(ImprovedTube.storage) command from console.

I don't know how to do it. There is no result when I paste it on YT page image

raszpl commented 6 months ago

paste JSON.stringify(ImprovedTube.storage) after blue > and hit enter

xeophyte commented 6 months ago

'{"ads":"all_videos","always_show_progress_bar":true,"below_player_loop":false,"below_player_pip":false,"below_player_screenshot":false,"channel_default_tab":"/videos","channel_trailer_autoplay":false,"description":"normal","duration_with_speed":true,"header_position":"hover_on_video_page","header_transparent":true,"hide_clip_button":"hidden","hide_download_button":"hidden","hide_more_button":false,"hide_report_button":true,"hide_save_button":"normal","hide_share_button":"hidden","hide_thanks_button":"hidden","hide_voice_search_button":true,"improvedtube_home":"list","it_analyzer":true,"it_blocklist":true,"it_channel":true,"it_mixer":true,"it_playlist":true,"it_shortcuts":false,"it_themes":true,"language":"en","layer_animation_scale":"1","likes":"normal","livechat":"collapsed","mini_player":true,"only_one_player_instance_playing":true,"player_always_repeat":false,"player_autoplay":true,"player_autoplay_button":true,"player_force_speed_on_music":false,"player_forced_playback_speed":false,"player_hide_controls":"off","player_loudness_normalization":true,"player_miniplayer_button":true,"player_playback_speed":1.25,"player_quality":"hd1080","player_remaining_duration":true,"player_repeat_button":true,"player_screen_button":true,"player_show_cards_on_mouse_hover":true,"player_transparent_background":false,"player_view_button":true,"red_dislike_button":true,"related_videos":"hidetabs","remove_home_page_shorts":true,"remove_subscriptions_shorts":true,"shortcut_decrease_playback_speed":{"alt":false,"ctrl":false,"keys":{"40":{"code":"ArrowDown","key":"ArrowDown"}},"shift":false,"wheel":0},"shortcut_decrease_volume":{"alt":false,"ctrl":false,"keys":{"98":{"code":"Numpad2","key":"2"}},"shift":false,"wheel":0},"shortcut_increase_playback_speed":{"alt":false,"ctrl":false,"keys":{"38":{"code":"ArrowUp","key":"ArrowUp"}},"shift":false,"wheel":0},"shortcut_increase_volume":{"alt":false,"ctrl":false,"keys":{"104":{"code":"Numpad8","key":"8"}},"shift":false,"wheel":0},"shortcut_next_video":{"alt":false,"ctrl":false,"keys":{"190":{"code":"Period","key":"."}},"shift":false,"wheel":0},"shortcut_playback_speed_step":0.25,"shortcut_prev_video":{"alt":false,"ctrl":false,"keys":{"188":{"code":"Comma","key":","}},"shift":false,"wheel":0},"theme":"dark","theme_primary_color":[200,200,200],"theme_text_color":[25,25,25],"thumbnails_hide":false,"thumbnails_right":false,"up_next_autoplay":true}'

raszpl commented 6 months ago

you didnt copy the whole thing :( paste command, press Enter, then whole config will appear, then double click it and copy/paste


( edit: @xeophyte exported the ImprovedTube settings )

DrNopt commented 6 months ago

Firefox, and win 11. Right click a video and choose "Open in new tab", video opens in pause. Should auto play. When i open i current tab (just click) it works every time. Default settings beside "Forced theater mode" and "Player size" to full height. Cannot find "player.js" in any place. Where is it in Firefox?

Jerrk commented 6 months ago

Ok, since we have couple of you here able to trigger this reliably. Experiment:

* search for /js&css/web-accessible/player.js file on your disk, should be in Chrome \User Data\Default\Extensions\ directory somewhere.

* open in text editor

* search for "setTimeout(function () {  video.pauseVideo();  }); " and delete this line

* save file

* reload YT page, usually works off the bat, sometimes requires manually reloading extensions or just restarting browser.

didnt do anything for me.

C:\Users\Jerrk\AppData\Local\Chromium\User Data\Default\Extensions\bnomihfieiccainjcjblhegjgglakjdd\4.826_0\js&css\web-accessible\www.youtube.com\player.js

just to make sure it was correct file, can you also paste full location of /js&css/web-accessible/player.js you were editing? and copy result of JSON.stringify(ImprovedTube.storage) command from console. the only other spot where extension tries to pause is with enabled playerAutopauseWhenSwitchingTabs and pause message https://github.com/search?q=repo%3Acode-charity%2Fyoutube%20pauseVideo&type=code, but those dont fire on their own

output from JSON.stringify(ImprovedTube.storage)

{"ads":"block_all","always_show_progress_bar":false,"analyzer_activation":false,"below_player_loop":false,"below_player_pip":false,"below_player_screenshot":false,"blacklist_activate":false,"channel_default_tab":"/videos","channel_play_all_button":true,"channel_trailer_autoplay":false,"channel_videos_count":true,"chapters":false,"collapse_of_subscription_sections":true,"compactSpacing":false,"default_content_country":"SE","description":"normal","duration_with_speed":true,"forced_theater_mode":true,"ga":1668365621239,"header_hide_country_code":true,"header_hide_right_buttons":false,"header_improve_logo":false,"header_position":"hover_on_video_page","hide_animated_thumbnails":true,"hide_footer":true,"hide_gradient_bottom":false,"hide_more_button":true,"hide_playlist":false,"hide_save_button":true,"hide_share_button":false,"hide_thumbnail_overlay":true,"hide_voice_search_button":true,"how_long_ago_the_video_was_uploaded":true,"improvedtube_home":"list","limit_page_width":true,"livechat":"normal","mark_watched_videos":true,"no_page_margin":false,"only_one_player_instance_playing":false,"open_new_tab":true,"player_SDR":false,"player_ads":"block_all","player_always_repeat":false,"player_autofullscreen":true,"player_autopause_when_switching_tabs":false,"player_autoplay":true,"player_dont_speed_education":false,"player_force_speed_on_music":false,"player_forced_playback_speed":true,"player_forced_volume":true,"player_hd_thumbnail":true,"player_hide_annotations":true,"player_hide_cards":true,"player_loudness_normalization":false,"player_playback_speed":2,"player_popup_button":true,"player_quality":"hd1080","player_remaining_duration":true,"player_repeat_button":false,"player_rotate_button":true,"player_screenshot_button":true,"player_show_cards_on_mouse_hover":true,"player_size":"full_window","playlist_repeat":false,"playlist_reverse":true,"playlist_shuffle":false,"red_dislike_button":true,"related_videos":"collapsed","remove_history_shorts":true,"remove_home_page_shorts":true,"remove_related_search_results":true,"remove_shorts_reel_search_results":true,"remove_subscriptions_shorts":true,"remove_trending_shorts":true,"schedule":"system_peference_dark","shortcut_decrease_playback_speed":{"alt":false,"ctrl":false,"keys":{"189":{"code":"Slash","key":"-"}},"shift":false,"wheel":0},"shortcut_increase_playback_speed":{"alt":false,"ctrl":false,"keys":{"187":{"code":"Minus","key":"+"}},"shift":false,"wheel":0},"shortcut_playback_speed_step":0.25,"sidebar_left":false,"theme":"black","theme_primary_color":[200,200,200],"theme_text_color":[25,25,25],"thumbnails_hide":true,"thumbnails_quality":"maxresdefault","thumbnails_right":false,"title_version":true,"track_watched_videos":true,"transcript":false,"up_next_autoplay":false,"watched":-----1MB of watched info-----,"youtube_home_page":"/feed/subscriptions","youtube_language":"en"}

Clearing cookies and site data for youtube and google fixed the issue again, same as just hitting the i key twice to switch to miniplayer and back.


I don't actually think that the problem is with improvedtube since i have another extension youtube custom speed that has the exact same issue where it will not load when opening a video in a new tab, but will load if i activate the miniplayer on and off. same behaviour when navigating to a different video it will just work.

I've also noticed that when loading a video in a new tab, the youtube page seems to delay the video load for some reason (ad-blocking maybe?) which may be the issue that i'm running in to. chrome_HicsfEonoC

This is the load after clearing cookies: chrome_9reAJ2Mmo1

It both autoplays AND goes into fullscreen as expected, youtube custom speed also loads as expected image chrome_woZOxSyFl0

So maybe improvedtube can run a refresh on the player element if it can detect that the settings did not load properly (like toggling the miniplayer does)? if that is even possible

xeophyte commented 6 months ago

I cleared cookies and site data for youtube and google and:

Evoden1 commented 6 months ago

I cleared cookies and site data for youtube and google and:

* when I'm not logged in YT: autoplay works

* when I'm logged in YT: autoplay doesn't work

Same here

raszpl commented 6 months ago

looking at Jerrk and xeophyte config it seems its not ImproveTube pausing/stopping video from playing, its YT doing something weird on its own :( One more test, Edit \AppData\Local\Vivaldi\User Data\Default\Extensions\bnomihfieiccainjcjblhegjgglakjdd\4.826_0\js&css\web-accessible\functions.js line 326 HTMLMediaElement.prototype.play = (function (original) { and change it to HTMLMediaElement.prototype.play_disabled = (function (original) { and restart browser. This will Entirely disable ImproveTube from manipulating Youtube Video element play.

xeophyte commented 6 months ago

With HTMLMediaElement.prototype.play_disabled = (function (original) { autoplay works, even without restarting the browser.

Jerrk commented 6 months ago

since i recently cleared cookies autoplay works as intended so changing line 326 to HTMLMediaElement.prototype.play_disabled = (function (original) { didnt do anything, autoplay still works.

I'll try it again when youtube decides its time 🙂

Evoden1 commented 6 months ago

looking at Jerrk and xeophyte config it seems its not ImproveTube pausing/stopping video from playing, its YT doing something weird on its own :( One more test, Edit \AppData\Local\Vivaldi\User Data\Default\Extensions\bnomihfieiccainjcjblhegjgglakjdd\4.826_0\js&css\web-accessible\functions.js line 326 HTMLMediaElement.prototype.play = (function (original) { and change it to HTMLMediaElement.prototype.play_disabled = (function (original) { and restart browser. This will Entirely disable ImproveTube from manipulating Youtube Video element play.

Where can I find Firefox's functions.js? I've searched the entire PC using everything and couldn't find it

Evoden1 commented 6 months ago

I got it.

Is it the .xpi under \Mozilla\Firefox\Profiles\MY-PROFILE\extensions, right? All I have to do is convert it to a rar archive, right? and edit from there?

Evoden1 commented 6 months ago

Firefox addons are signed, so modifying them is not so straight forward

so it's impossible? I'm using Firefox beta not nightly

raszpl commented 6 months ago

Is there something like developer mode in Firefox to install unpacked extension temporarily for a test?

xeophyte commented 6 months ago

There is an option in the addon menu to install addon from the file or debug mode where you can temporarily load the add-on. You can there also get UUID of each addon to locate it on the disk easier.

Jerrk commented 6 months ago

looking at Jerrk and xeophyte config it seems its not ImproveTube pausing/stopping video from playing, its YT doing something weird on its own :( One more test, Edit \AppData\Local\Vivaldi\User Data\Default\Extensions\bnomihfieiccainjcjblhegjgglakjdd\4.826_0\js&css\web-accessible\functions.js line 326 HTMLMediaElement.prototype.play = (function (original) { and change it to HTMLMediaElement.prototype.play_disabled = (function (original) { and restart browser. This will Entirely disable ImproveTube from manipulating Youtube Video element play.

now with the issue back:

appending _disabled to the function in line 326 does actually autoplay the videos now.

Removing _disabled from the function name disables autoplay again.

Evoden1 commented 6 months ago

There is an option in the addon menu to install addon from the file or debug mode where you can temporarily load the add-on. You can there also get UUID of each addon to locate it on the disk easier.

I added it temporarily, and the autoplay problem is fixed But is there a way to permanently load the extension?

When I try to install add-on from file and select the modified ImproveYoutube

It says, "This add-on could not be installed because it appears to be corrupt."

raszpl commented 6 months ago

now with the issue back:

appending _disabled to the function in line 326 does actually autoplay the videos now. Removing _disabled from the function name disables autoplay again.

:o amazing, I didnt think this would work :] there is nothing in there that jumps at me as having potential to screw with YT autoplay. Just to be sure, you added _disabled to HTMLMediaElement.prototype.play and not ImprovedTube.playerOnPlay ? the second one will just make extension crash and not load.

It would make this the offending code:

    HTMLMediaElement.prototype.play = (function (original) {
        return function () {
            this.removeEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);
            this.addEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);

            this.removeEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);
            this.addEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);

            this.removeEventListener('pause', ImprovedTube.playerOnPause, true);
            this.addEventListener('pause', ImprovedTube.playerOnPause, true);

            this.removeEventListener('ended', ImprovedTube.playerOnEnded, true);
            this.addEventListener('ended', ImprovedTube.playerOnEnded, true);

            ImprovedTube.autoplayDisable();
            ImprovedTube.playerLoudnessNormalization();
            ImprovedTube.playerCinemaModeEnable();

            return original.apply(this, arguments);
        }
    })(HTMLMediaElement.prototype.play);

We can play an elimination game, keep commenting out lines until autoplay starts working. Lets start with

            //this.removeEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);
            //this.addEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);

            //this.removeEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);
            //this.addEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);

            //this.removeEventListener('pause', ImprovedTube.playerOnPause, true);
            //this.addEventListener('pause', ImprovedTube.playerOnPause, true);

            //this.removeEventListener('ended', ImprovedTube.playerOnEnded, true);
            //this.addEventListener('ended', ImprovedTube.playerOnEnded, true);

if that doesnt help

//ImprovedTube.playerLoudnessNormalization();

then

//ImprovedTube.playerCinemaModeEnable();

and finally last

//ImprovedTube.autoplayDisable();

lets see where you need to stop to make YT happy.

Evoden1 commented 6 months ago

now with the issue back: appending _disabled to the function in line 326 does actually autoplay the videos now. Removing _disabled from the function name disables autoplay again.

:o amazing, I didnt think this would work :] there is nothing in there that jumps at me as having potential to screw with YT autoplay. Just to be sure, you added _disabled to HTMLMediaElement.prototype.play and not ImprovedTube.playerOnPlay ? the second one will just make extension crash and not load.

It would make this the offending code:

  HTMLMediaElement.prototype.play = (function (original) {
      return function () {
          this.removeEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);
          this.addEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);

          this.removeEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);
          this.addEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);

          this.removeEventListener('pause', ImprovedTube.playerOnPause, true);
          this.addEventListener('pause', ImprovedTube.playerOnPause, true);

          this.removeEventListener('ended', ImprovedTube.playerOnEnded, true);
          this.addEventListener('ended', ImprovedTube.playerOnEnded, true);

          ImprovedTube.autoplayDisable();
          ImprovedTube.playerLoudnessNormalization();
          ImprovedTube.playerCinemaModeEnable();

          return original.apply(this, arguments);
      }
  })(HTMLMediaElement.prototype.play);

We can play an elimination game, keep commenting out lines until autoplay starts working. Lets start with

          //this.removeEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);
          //this.addEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);

          //this.removeEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);
          //this.addEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);

          //this.removeEventListener('pause', ImprovedTube.playerOnPause, true);
          //this.addEventListener('pause', ImprovedTube.playerOnPause, true);

          //this.removeEventListener('ended', ImprovedTube.playerOnEnded, true);
          //this.addEventListener('ended', ImprovedTube.playerOnEnded, true);

if that doesnt help

//ImprovedTube.playerLoudnessNormalization();

then

//ImprovedTube.playerCinemaModeEnable();

and finally last

//ImprovedTube.autoplayDisable();

lets see where you need to stop to make YT happy.

I tried it on Firefox beta "temporarily load the add-on option"

    HTMLMediaElement.prototype.play = (function (original) {
        return function () {
            this.removeEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);
            this.addEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);

            this.removeEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);
            this.addEventListener('timeupdate', ImprovedTube.playerOnTimeUpdate);

            this.removeEventListener('pause', ImprovedTube.playerOnPause, true);
            this.addEventListener('pause', ImprovedTube.playerOnPause, true);

            this.removeEventListener('ended', ImprovedTube.playerOnEnded, true);
            this.addEventListener('ended', ImprovedTube.playerOnEnded, true);

            //ImprovedTube.autoplay(); 
            ImprovedTube.playerLoudnessNormalization();

            return original.apply(this, arguments);
        }
    })(HTMLMediaElement.prototype.play);
};

ImprovedTube.autoplay(); I commented this one only, and the autoplay problem is fixed 

now it can autoplay videos opened in new tabs

PS: I commented the others but it didn't make any difference  ImprovedTube.autoplay(); did

sonal-g123 commented 6 months ago

This is way too technical for me. Please, someone tag me when they get a simple solution/method to this issue. I use Chrome.

xeophyte commented 6 months ago

Just to be sure, you added _disabled to HTMLMediaElement.prototype.play and not ImprovedTube.playerOnPlay ?

Yes. _disabled added only to HTMLMediaElement.prototype.play.

//ImprovedTube.playerCinemaModeEnable();

I don't have anything with CinemaMode in my functions.js.

I don't have ImprovedTube.autoplayDisable();, but ImprovedTube.autoplay(); and autoplay works only when I comment it out, so //ImprovedTube.autoplay(); is enough to fix it.

raszpl commented 6 months ago

Ok, good. Wee are narrowing it down :) So this is our suspect in \js&css\web-accessible\www.youtube.com\player.js top of the file:

ImprovedTube.autoplay = function () {
    var video = ImprovedTube.elements.player;
    if (ImprovedTube.video_url !== location.href) {
        ImprovedTube.ignore_autoplay_off = false;
    }
    // if (allow autoplay is false) and  (no ads playing) and
    // ( there is a video and ( (it is not in a playlist and  auto play is off ) or ( playlist auto play is off and it is not in a playlist ) ) ) or (if we are in a channel and the channel trailer autoplay is off)  )
    if (ImprovedTube.ignore_autoplay_off === false && video.classList.contains('ad-showing') === false &&
        ( 
// quick fix #1703  thanks to @AirRaid#9957
            (/* document.documentElement.dataset.pageType === "video" */ location.href.indexOf('/watch?') !== -1 && ((location.href.indexOf('list=') === -1 && ImprovedTube.storage.player_autoplay === false) || (ImprovedTube.storage.playlist_autoplay === false && location.href.indexOf('list=') !== -1))) ||
            (/* document.documentElement.dataset.pageType === "channel" */ ImprovedTube.regex.channel.test(location.href) && ImprovedTube.storage.channel_trailer_autoplay === false)
        )
    )         
    {if (!ImprovedTube.autoplayDeniedOnce) {  
     setTimeout(function () {  video.pauseVideo();  });        
     ImprovedTube.autoplayDeniedOnce = true; 
    } else { console.log("autoplay:off - should we pause here again?"); } }
};

uncomment all previous changes back and lets look at autoplay then. Somehow its pausing YT without being asked to pause? Lets start with my previous obvious suggestion, comment out //setTimeout(function () { video.pauseVideo(); });

xeophyte commented 6 months ago

I don't have this video.pauseVideo(); in either of these two .js files. This is my autoplay section:

/*------------------------------------------------------------------------------
AUTOPLAY
------------------------------------------------------------------------------*/
ImprovedTube.autoplay = function () {
    var video = ImprovedTube.elements.player;
    if (ImprovedTube.video_url !== location.href) {
        ImprovedTube.ignore_autoplay_off = false;
    }
    // if (allow autoplay is false) and  (no ads playing) and
    // ( there is a video and ( (it is not in a playlist and  auto play is off ) or ( playlist auto play is off and it is not in a playlist ) ) ) or (if we are in a channel and the channel trailer autoplay is off)  )
    if (ImprovedTube.ignore_autoplay_off === false && video.classList.contains('ad-showing') === false &&
        ( 
// quick fix #1703  thanks to @AirRaid#9957
            (/* document.documentElement.dataset.pageType === "video" */ location.href.indexOf('/watch?') !== -1 && ((location.href.indexOf('list=') === -1 && ImprovedTube.storage.player_autoplay === false) || (ImprovedTube.storage.playlist_autoplay === false && location.href.indexOf('list=') !== -1))) ||
            (/* document.documentElement.dataset.pageType === "channel" */ ImprovedTube.regex.channel.test(location.href) && ImprovedTube.storage.channel_trailer_autoplay === false)
        )
    )         
    {if (!ImprovedTube.autoplayDeniedOnce) {  
     ImprovedTube.autoplayDeniedOnce = true; 
    } else { console.log("autoplay:off - should we pause here again?"); } }
};

Should I add this setTimeout(function () { video.pauseVideo(); }); line? And btw, how do you add the code to this frame with code style preserved when you write the post?

Evoden1 commented 6 months ago

Ok, good. Wee are narrowing it down :) So this is our suspect in \js&css\web-accessible\www.youtube.com\player.js top of the file:

ImprovedTube.autoplay = function () {
    var video = ImprovedTube.elements.player;
    if (ImprovedTube.video_url !== location.href) {
        ImprovedTube.ignore_autoplay_off = false;
    }
    // if (allow autoplay is false) and  (no ads playing) and
  // ( there is a video and ( (it is not in a playlist and  auto play is off ) or ( playlist auto play is off and it is not in a playlist ) ) ) or (if we are in a channel and the channel trailer autoplay is off)  )
    if (ImprovedTube.ignore_autoplay_off === false && video.classList.contains('ad-showing') === false &&
        ( 
// quick fix #1703  thanks to @AirRaid#9957
            (/* document.documentElement.dataset.pageType === "video" */ location.href.indexOf('/watch?') !== -1 && ((location.href.indexOf('list=') === -1 && ImprovedTube.storage.player_autoplay === false) || (ImprovedTube.storage.playlist_autoplay === false && location.href.indexOf('list=') !== -1))) ||
            (/* document.documentElement.dataset.pageType === "channel" */ ImprovedTube.regex.channel.test(location.href) && ImprovedTube.storage.channel_trailer_autoplay === false)
        )
    )         
  {if (!ImprovedTube.autoplayDeniedOnce) {  
   setTimeout(function () {  video.pauseVideo();  });        
   ImprovedTube.autoplayDeniedOnce = true; 
  } else { console.log("autoplay:off - should we pause here again?"); } }
};

uncomment all previous changes back and lets look at autoplay then. Somehow its pausing YT without being asked to pause? Lets start with my previous obvious suggestion, comment out //setTimeout(function () { video.pauseVideo(); });

Ok, I've restored function.js back to its default state so autoplay stopped working

/*------------------------------------------------------------------------------
AUTOPLAY
------------------------------------------------------------------------------*/
ImprovedTube.autoplay = function () {
    var video = ImprovedTube.elements.player;
    if (ImprovedTube.video_url !== location.href) {
        ImprovedTube.ignore_autoplay_off = false;
    }
    // if (allow autoplay is false) and  (no ads playing) and
    // ( there is a video and ( (it is not in a playlist and  auto play is off ) or ( playlist auto play is off and it is not in a playlist ) ) ) or (if we are in a channel and the channel trailer autoplay is off)  )
    if (ImprovedTube.ignore_autoplay_off === false && video.classList.contains('ad-showing') === false &&
        ( 
// quick fix #1703  thanks to @AirRaid#9957
            (/* document.documentElement.dataset.pageType === "video" */ location.href.indexOf('/watch?') !== -1 && ((location.href.indexOf('list=') === -1 && ImprovedTube.storage.player_autoplay === false) || (ImprovedTube.storage.playlist_autoplay === false && location.href.indexOf('list=') !== -1))) ||
            (/* document.documentElement.dataset.pageType === "channel" */ ImprovedTube.regex.channel.test(location.href) && ImprovedTube.storage.channel_trailer_autoplay === false)
        )
    )         
    {if (!ImprovedTube.autoplayDeniedOnce) {  
    //setTimeout(function () {  video.pauseVideo();  });        
     ImprovedTube.autoplayDeniedOnce = true; 
    } else { console.log("autoplay:off - should we pause here again?"); } }
};

//setTimeout(function () { video.pauseVideo(); }); I've commented this line and the autoplay didn't work

raszpl commented 6 months ago

I don't have this video.pauseVideo(); in either of these two .js files.

oh, so you deleted it when I asked earlier, and this still didnt cure YT?

Should I add this setTimeout(function () { video.pauseVideo(); }); line?

no, you not having it and YT still not autoplaying further narrows things down.

And btw, how do you add the code to this frame with code style preserved when you write the post?

paste code, select code, press <> icon on top of Edit window (fifth icon).

//setTimeout(function () { video.pauseVideo(); }); I've commented this line and the autoplay didn't work

two people same results . Sadly this result makes no sense to me :0 This is the only active thing we do in this function. Only thing that comes to my mind is this function somehow crashing when YT calls it early because one of the touched variables doesnt exist yet. lets start with modifying comparison to :

if (ImprovedTube.ignore_autoplay_off === false && video.classList.contains('ad-showing')
//if (ImprovedTube.ignore_autoplay_off === false && video.classList.contains('ad-showing') === false &&
//        ( 
// quick fix #1703  thanks to @AirRaid#9957
//            (/* document.documentElement.dataset.pageType === "video" */ location.href.indexOf('/watch?') !== -1 && ((location.href.indexOf('list=') === -1 && ImprovedTube.storage.player_autoplay === false) || (ImprovedTube.storage.playlist_autoplay === false && location.href.indexOf('list=') !== -1))) ||
//            (/* document.documentElement.dataset.pageType === "channel" */ ImprovedTube.regex.channel.test(location.href) && ImprovedTube.storage.channel_trailer_autoplay === false)
//        )
    )

ooor, replace var video = ImprovedTube.elements.player; with:

    console.log('ImprovedTube.autoplay !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
    console.log(ImprovedTube.elements.player);
    var video = ImprovedTube.elements.player;
    console.log(ImprovedTube.video_url, ImprovedTube.video_url !== location.href);
    console.log(ImprovedTube.ignore_autoplay_off);
    console.log(video.classList.contains('ad-showing'));
    console.log(ImprovedTube.storage.player_autoplay);
    console.log(ImprovedTube.regex.channel);
    console.log(ImprovedTube.autoplayDeniedOnce);
    console.log('ImprovedTube.autoplay ______________________________________________________');

restart browser, and when you trigger failing autoplay open console and copy from console everything between ImprovedTube.autoplay !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ImprovedTube.autoplay __