code-charity / youtube

[top~1 open YouTube & Video web-extension] Enrich your experience & choice! 🧰180+ options & 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.33k stars 504 forks source link

"Web-accessible files" (including js&css/web-accessible/init.js) load late/r #2459

Open ImprovedTube opened 1 week ago

ImprovedTube commented 1 week ago

What might web-accessible even be good for?

it might helps to keep frequently called small files in the browser's in-memory cache (to check exactly)
and use APIs when CSPs might not (music detection code)

If we got rid of /web-accessible/ moving all code to /extension/ there would be no delay, we would be up and running before YT even starts loading from the server.

Looking forward! So maybe it is only good for API calls. And files /photos that can/should wait, like it sounds, or a secondary.css)

(Separation:)

in our extension code was made web-accessible along with a Manifest3 guide? Dec7 2021 - Migrated to manifest v3 ( "web_accessible_resources":[{"resources": ["youtube-scripts.js"],"matches":["https://www.youtube.com/*"]}], )
more: https://github.com/code-charity/youtube/pull/2299#issuecomment-2128317539 )


Web-accessible files load late/r

In Firefox loading random YT clip the first js&css/web-accessible/core.js is injected right at the top, while last js&css/web-accessible/init.js is the last node in HTML document injected long after whole thing loaded. This means there is a high chance browser already started executing YT javascript before our js&css/web-accessible/init.js runs. Bad for intercepting autoplay, bad for codecs, might even miss some early nodes in ImprovedTube.ytElementsHandler()

👍 this can be documentation for this project as long as it is like this!

dont take my word for it, test test test and verify. Might be my computer or config after all. I just rechecked and this time init.js lands just after HEAD, so it might have been my bogged Browser session. But even after HEAD is too slow - YT JS files loaded in HEAD might have started running at this point.


open devtools and look where js&css/web-accessible/ files are located in the YT html Browser is able to inject all

              "js&css/extension/core.js",
              "js&css/extension/functions.js",
              "js&css/extension/www.youtube.com/.../....js",
              "js&css/extension/init.js"

before HTML is even fetched from YT server, but our manually injected files are injected with huge delay. In Chrome all land after HEAD. In FF and Vivaldi first few somehow manage to squeeze just before HEAD. If we got rid of /web-accessible/ moving all code to /extension/ there would be no delay, we would be up and running before YT even starts loading from the server.

ImprovedTube commented 1 week ago

thanks to @raszpl #2299