Repository navigation
Fix: Resolves Firefox thumbnail not loading issue - #3691
Merged
Merged
Conversation
Member
Author
|
@ImprovedTube |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #3235, #2310
Root Cause of the Bug
The issue where thumbnails fail to load indefinitely in Firefox-based browsers is caused by direct DOM mutation interacting with Firefox's Enhanced Tracking Protection (ETP) and strict CORS policies. The previous logic directly replaced the
srcattribute of the live<img>element. When Firefox blocked the modified high-resolution image request, the failure occurred silently at the network level without triggering the standardonerrorDOM event. Consequently, the fallback mechanism failed to execute, leaving the user with a permanently broken thumbnail.Fixes and Architectural Improvements
Implemented Off-Screen Preloading: The logic now uses an off-screen
Image()object to fetch and test the high-resolution URL asynchronously.This ensures the live page is never put at risk. The visible thumbnail's
srcis only swapped if the background download is strictly successful. If the browser blocks the request or the image is missing, the original thumbnail remains untouched.Video ID Identity Verification: Replaced the fragile string-matching logic (which checked URLs for quality tokens like
hqdefault) with a robust regex that extracts the unique 11-character YouTube Video ID.YouTube's Single Page Application (SPA) natively recycles
<img>tags for new videos. Comparing exact Video IDs prevents "poisoned state" glitches where recycled DOM nodes would refuse to update.Race Condition Prevention: Added a strict state check (
thumbnail.dataset.defaultSrc === originalSrc) inside the asynchronous image load callback.This guarantees that rapid user scrolling does not cause a delayed high-resolution image from a previous video to overwrite the thumbnail of a newly recycled DOM node.
Infinite Scroll Support: Added explicit handling for
childListmutations within theMutationObserver.The previous observer ignored newly injected DOM nodes. This addition ensures thumbnails are upgraded instantly as new videos are loaded into the page during downward scrolling.
Stale Closure Resolution: The observer is now actively disconnected and re-instantiated during execution.
This resolves a bug where the observer was permanently trapped in a stale closure, causing it to ignore user configuration changes until a full page reload.
Query Parameter Stripping: The logic now strips trailing query parameters (e.g.,
?sqp=...) from the base URL prior to string replacement.YouTube servers frequently reject
maxresdefaultupgrades if the request carries cryptographic signatures meant for lower-resolution images. Stripping these significantly increases the upgrade success rate.