Repository navigation
feat(youtube): block YouTube ads (player data pruning + player fallback) - #14
Merged
Merged
Conversation
Merges the two YouTube approaches from #10 and #11: - youtube-inject.js (MAIN world, document_start): removes playerAds, adPlacements, adSlots and adBreakHeartbeatParams from the player response embedded in the page (ytInitialPlayerResponse, missed so far on a direct /watch load) and from youtubei player/next/reel responses (fetch, incl. Request objects, and XHR text/json). The player never schedules the ad. - It can't read extension storage, so background.js registers it with chrome.scripting only while protection is active and excludes allow-listed domains: pause, off and allow list apply from the first script of the page. Registration is serialized to avoid duplicate ids. - youtube.js (isolated, all frames incl. youtube-nocookie): fallback when an ad still starts. Hides and mutes it, fast-forwards it with a per-source guard and a grace period after a source change so the real video is never sent to its end, clicks skip, restores the sound it muted. Ad slots (masthead, feed, banners) follow the cosmetic setting. - rules: youtube.com/api/stats/ads, /pagead/, /ptracking (other doubleclick hosts are already covered by rule 1). - CI: syntax-check both scripts and the runtime-registered file. Closes #10, closes #11. Co-authored-by: PoPoGH <quentinlorente2502@gmail.com>
This was referenced Sep 13, 2026
Base automatically changed from
fix/whitelist-pause-counter-filters
to
main
September 13, 2026 10:27
AbrahamOP
changed the base branch from
fix/whitelist-pause-counter-filters
to
main
September 13, 2026 10:27
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.
Fusionne les deux propositions YouTube, #10 de @PoPoGH et #11, en gardant le meilleur de chacune.
Comment
youtube-inject.js(world MAIN,document_start) : retireplayerAds,adPlacements,adSlotsetadBreakHeartbeatParamsdes données du lecteur, qui ne programme donc jamais la pub. Sources couvertes :ytInitialPlayerResponseintégré à la page. feat(youtube): block video ads via API interception + auto-skip #10 ne le couvrait pas, alors que c'est lui qui porte les pubs au premier chargement d'une vidéo.youtubei/v1/player|next|reelenfetch(y comprisRequest) et en XHR (texte ou JSON).chrome.scripting) : le script en world MAIN ne peut pas lire le stockage. background.js ne l'enregistre donc que si la protection est active, et exclut les domaines de la liste blanche. Pause, OFF et liste blanche s'appliquent ainsi dès le premier script de la page, sans course. Les appels sont sérialisés, sinon on obtient une erreurDuplicate script ID, reproduite en test.youtube.js(isolé, toutes les frames, youtube-nocookie compris) : filet de sécurité si une pub démarre quand même. Il la masque, coupe le son, l'avance à la fin et clique « Passer ». Deux garde-fous repris de feat(youtube): block video ads via API interception + auto-skip #10 : une avance par source, et 150 ms de délai après un changement de source, pour ne jamais envoyer la vraie vidéo à la fin. Il rétablit ensuite le son qu'il a lui-même coupé. Les emplacements pub (masthead, fil, bannières) suivent le réglage « Nettoyage visuel ».youtube.com/api/stats/ads,/pagead/,/ptracking. Les autres hôtes doubleclick de feat(youtube): block video ads via API interception + auto-skip #10 sont déjà couverts par la règle 1.Nouvelle permission
scripting. Elle n'ajoute pas d'avertissement, puisque les permissions d'hôte<all_urls>sont déjà là.Tests
ytInitialPlayerResponseÀ valider à la main dans un vrai Chrome : pré-roll et mid-roll sur plusieurs vidéos, Shorts, YouTube Music, embed youtube-nocookie.