code-charity / youtube

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

Update player.js playerQualityWithoutFocus breaks on switching tabs #2299

Closed raszpl closed 1 month ago

raszpl commented 1 month ago

https://github.com/code-charity/youtube/blob/d8065714b67e4bbb891b11eedd72ef68f0afed38/background.js#L179-L202

sends additional second blur message on tab switch

this https://github.com/code-charity/youtube/blob/d8065714b67e4bbb891b11eedd72ef68f0afed38/js%26css/web-accessible/www.youtube.com/player.js#L411 sets qualityBeforeBlur again when already minimized, this time to this.storage.player_quality_without_focus. After rocusing back video quality is "restored" to qualityBeforeBlur === this.storage.player_quality_without_focus.

background.js is sending second blur event. Its sending multiple ones when whole browser is minimized for example, or tab switched. Dont know why and if its needed. Definitely sending events to tabs where extension is not running is not good.

ImprovedTube commented 1 month ago

hi @rasz_pl

could also use tab.id 😁 https://github.com/code-charity/youtube/blob/6538d6af42c27635489b2b19c294377042f1d4c9/background.js#L162


and to undo if the low quality makes it to a new session...? :

if (ImprovedTube.qualityBeforeBlur) { ... } 
else { if ( qualityWithoutFocus === player.getPlaybackQuality() ) {ImprovedTube.playerQuality(ImprovedTube.player_quality || undefined); } ) 
raszpl commented 1 month ago

hi @rasz_pl

could also use tab.id 😁

should. I dont know why background.js is doing what its doing, but whatever its doing its doing too much of it to elaborate: why is this code in background.js to begin with? all this mess(double messages, messaging all the tabs) can be replaced by sticking

window.addEventListener("blur", (event) => {
});
window.addEventListener("focus", (event) => {
});

somewhere around here https://github.com/code-charity/youtube/blob/8223c7d3cd56d465003c8196e301732855ee443f/js%26css/web-accessible/init.js#L134

ImprovedTube commented 1 month ago

hi! @raszpl

idk, previously assumed manifest3 broke it: https://github.com/code-charity/youtube/issues/1516#issuecomment-1422957257

brings us back here: #1439 and #bugs+#important

version 3.965.zip ( = view repo at october7 2022 )

At least we should still look at 3.965 to fetch the features not migrated to 4.0 (Mixer, Analyzer & Custom CSS & JS) (and there might be more good code missing since 4.0)

( obvious change in 4.0 stuff was moving stuff from web-accessible youtube-scripts.js to content scripts:

    "content-scripts/extension-context/youtube-features/night-mode/night-mode.js",
    "content-scripts/extension-context/youtube-features/general/general.js",
    "content-scripts/extension-context/youtube-features/appearance/player/player.js",
    "content-scripts/extension-context/youtube-features/appearance/details/details.js",
    "content-scripts/extension-context/youtube-features/appearance/sidebar/sidebar.js",
    "content-scripts/extension-context/youtube-features/appearance/comments/comments.js",                   

And there was the plan to allow HTMLmediaelement features on all sites. Or integrate/invite https://github.com/xxxily/h5player / & https://greasyfork.org/en/scripts/30545. ( And care for top URLs like m.youtube & facebook.com/watch) (So that must be why the sub-folders were called "youtube" for 4.0 )