Skip to content

feat(youtube): block video ads via API interception + auto-skip - #10

Closed
PoPoGH wants to merge 1 commit into
AbrahamOP:mainfrom
PoPoGH:feat/youtube-adblock
Closed

PoPoGH wants to merge 1 commit into
AbrahamOP:mainfrom
PoPoGH:feat/youtube-adblock

Conversation

@PoPoGH

@PoPoGH PoPoGH commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds first-class YouTube ad blocking on top of the existing network/cosmetic filtering. Three layers, ordered by speed:

  1. youtube-inject.js (new) — runs in world: "MAIN" at document_start. Wraps window.fetch and XMLHttpRequest to intercept /youtubei/v1/player, /next, and /reel/reel_watch_sequence responses, recursively stripping playerAds, adPlacements, adSlots, adBreakHeartbeatParams. The player never tries to load an ad → instant video start.
  2. content.js — auto-skip fallback. Clicks the Skip button, fast-forwards non-skippable ads (currentTime = duration), mutes the moment ad-showing is detected. Per-source guard + 150ms loadstart suspension prevent the bug where the real video gets sent to the end. State (muted/playbackRate) is reset on every media swap.
  3. content.css — hides ad overlays / display ads / promo cards while ad-showing is set.

Also adds 5 DNR rules for YouTube-specific ad endpoints (/api/stats/ads, /pagead/, /ptracking, googleads.g.doubleclick.net, static.doubleclick.net).

The skip counter increments by one per skipped ad (guarded against double-counting via skippedSrc).

Test plan

  • Reload extension in chrome://extensions
  • Open a YouTube video known to serve pre-rolls — should start instantly with no ad visible/audible
  • Open a video with mid-roll markers — mid-rolls should not play
  • Confirm the actual video plays normally (no fast-forward, no premature seek to end)
  • Confirm badge counter increases when ads are skipped
  • Confirm extension toggle (enabled = false) re-enables ads as expected
  • Cosmetic filtering for home/sidebar promoted content (ytd-display-ad-renderer, #masthead-ad, etc.)
  • Test on youtube-nocookie.com embeds

…-skip

- Inject MAIN-world script that strips playerAds/adPlacements from
  /youtubei/v1/player and /next responses so the player never tries
  to load ads (fastest path).
- Auto-skip fallback in content.js: clicks Skip button, fast-forwards
  non-skippable ads via currentTime=duration, with per-src guard and
  loadstart suspension to prevent skipping the real video.
- Mute applied immediately when ad-showing is detected (no audio leak).
- CSS hides ad overlays and the video element while ads play.
- New DNR rules for YouTube ad endpoints (pagead, ptracking, stats/ads,
  doubleclick subdomains).
- Counter increments per skipped YouTube ad.
@AbrahamOP

Copy link
Copy Markdown
Owner

Merci pour cette PR ! Ton interception de l'API du lecteur a été reprise dans #14. J'y ai ajouté la purge de ytInitialPlayerResponse et la prise en compte de la pause et de la liste blanche. Tu es crédité en co-auteur du commit. Je ferme celle-ci au profit de #14.

@AbrahamOP AbrahamOP closed this in 9592dd5 Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants