Fix: Add smart hardware check and network probe for HD thumbnails#3770
Open
AryaXDG wants to merge 1 commit intocode-charity:masterfrom
Open
Fix: Add smart hardware check and network probe for HD thumbnails#3770AryaXDG wants to merge 1 commit intocode-charity:masterfrom
AryaXDG wants to merge 1 commit intocode-charity:masterfrom
Conversation
rajanarahul93
suggested changes
Apr 11, 2026
| var rect = thumbnail.getBoundingClientRect(); | ||
| var physicalWidth = (rect.width || thumbnail.clientWidth || 0) * (window.devicePixelRatio || 1); | ||
|
|
||
| if (physicalWidth > 400 || physicalWidth === 0) { |
Contributor
There was a problem hiding this comment.
When physicalWidth === 0 the thumbnail has no layout (hidden, not in DOM, or mid-navigation). Rather than skipping safely, the probe fires anyway. This is the condition most likely to occur during SPA navigation when the player is being rebuilt. The probe result arrives after the fact and may apply to a stale DOM node.
Fix: Treat zero as "unknown/unsafe" and skip
d4783a9 to
0403173
Compare
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.
The PR addresses network rejection errors (404s) and significant data waste associated with the "HD Thumbnail" and "Thumbnails Quality" features.
Currently, the extension uses a "blind swap" approach to upgrade thumbnails, forcefully replacing
hqdefault.jpgstrings withmaxresdefault.jpg(1280px). If YouTube has not generated a high-res version for a specific video (very common for older uploads), the server rejects the request (404 Not Found), resulting in broken images, black boxes, and layout breaking. Furthermore, applying massive 1280px images to physically small screens (like smartphones) wastes significant bandwidth and battery life, as the required pixel density far exceeds what the human eye can perceive at normal viewing distances.This patch refactors the thumbnail upgrade logic to use a "Smart Hardware & Network Probe" architecture. It dynamically evaluates the user's physical screen resolution before offering the features in the UI, and silently pre-loads images to ensure they exist on YouTube's servers before altering the DOM.
Changes Included
appearance.jswith a backgroundImage()object probe. The engine now silently tests ifmaxresdefault.jpgexists. If YouTube returns a 404, it safely aborts and leaveshqdefault.jpgintact, completely eliminating broken thumbnail layouts.window.screen.width * window.devicePixelRatio) to determine the absolute physical pixel count of the user's display.on: { render: }logic to the Satus menu components inappearance.jsandgeneral.js. If the user's physical screen width is below 1000px (e.g., mobile phones, older tablets), the "HD Thumbnail" switch and "Thumbnails Quality" dropdown are completely hidden. This prevents users from activating data-heavy features their hardware cannot physically render.ImprovedTube.playerHdThumbnail) to accept specific element parameters (thumbnailElement || ImprovedTube.elements.player_thumbnail), ensuring the new smart logic scales safely across both the main video player and modern grid layouts.