Repository navigation
[FEATURE] Block YouTube ads in videos, Shorts and on the site - #31
Merged
Merged
Conversation
YouTube's in-video ads come inside its own player data, so network rules cannot block them. A page-world script, shared by WebKit and Chromium, removes ad placements before the player reads them, recovers from the playback stall YouTube imposes when its ads do not play, and hides sponsored slots. It follows each profile's content-blocking switch and site exceptions. The techniques port uBlock Origin's current YouTube filters. Live checks (logged out): without blocking, 15-33 s of ads before each video; with blocking, no ads and playback within 2-8 s in both engines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
Built-in YouTube ad blocking for WebKit and Chromium tabs:
It follows each profile's content blocking switch and its site exceptions: allowing
https://www.youtube.comthrough the blocker shows ads again. Settings explains this under the Enable rules switch.How
Engine/Shared/YouTubeAdBlock.swift: one page-world script, run at document start. It only acts on YouTube player hosts (not Studio or account pages). It ports uBlock Origin's current YouTube filters (GPL-3.0, credited inTHIRD_PARTY_NOTICES.md).WebKitPage.applyContentRules()installs the script in all frames and updates it when blocking or exceptions change. WebKit cannot remove a single user script, so the others are reinstalled unchanged.Testing
./Scripts/test.sh: 656 tests, 0 failures (3 skipped). New tests cover ad removal, site-slot hiding, exceptions and other sites, and user-script swapping that keeps other scripts.swift test: 13 Chromium adapter tests pass, including the rules-extension manifest.Limits
🤖 Generated with Claude Code