Skip to content

Add core ad blocking capabilities#8622

Open
CrisBarreiro wants to merge 5 commits into
feature/cris/ad-blocking/download-store-scriptletsfrom
feature/cris/ad-blocking/core-ad-blocking
Open

Add core ad blocking capabilities#8622
CrisBarreiro wants to merge 5 commits into
feature/cris/ad-blocking/download-store-scriptletsfrom
feature/cris/ad-blocking/core-ad-blocking

Conversation

@CrisBarreiro
Copy link
Copy Markdown
Collaborator

@CrisBarreiro CrisBarreiro commented May 19, 2026

Task/Issue URL: https://app.asana.com/1/137249556945/project/1212227266948491/task/1213078401808051?focus=true

Description

Add core ad blocking capabilities

Steps to test this PR

Feature 1

  • Fresh install the app
  • Open YouTube.com
  • Check logs for Feature not discoverable and Status checker rejected injection, skipping
  • Go to feature flag inventory and enable adBlockingExtension.isDiscoverable
  • Kill and reopen the app
  • Check logs for Feature not operational and Status checker rejected injection, skipping
  • Go to feature flag inventory and enable adBlockingExtension
  • Kill and reopen the app
  • Check logs for Empty payload, skipping
  • Browse through a few videos and check ads are shown

Feature 2

  • Apply Patch 1: Update RC URL
  • Fresh install the app
  • Open YouTube.com
  • Check logs for Feature not discoverable and Status checker rejected injection, skipping
  • Go to feature flag inventory and enable adBlockingExtension, and adBlockingExtension.isDiscoverable
  • Kill and reopen the app
  • Check logs for Injecting script
  • Browse through a few videos and check ads are not shown

Patches

Patch 1: Update RC URL

Subject: [PATCH] Update privacy-config URL
---
Index: privacy-config/privacy-config-api/src/main/java/com/duckduckgo/privacy/config/api/PrivacyFeatureName.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/privacy-config/privacy-config-api/src/main/java/com/duckduckgo/privacy/config/api/PrivacyFeatureName.kt b/privacy-config/privacy-config-api/src/main/java/com/duckduckgo/privacy/config/api/PrivacyFeatureName.kt
--- a/privacy-config/privacy-config-api/src/main/java/com/duckduckgo/privacy/config/api/PrivacyFeatureName.kt	(revision ca28c5a412606fefb8bcee8532f901d9fe30b55c)
+++ b/privacy-config/privacy-config-api/src/main/java/com/duckduckgo/privacy/config/api/PrivacyFeatureName.kt	(date 1779203719053)
@@ -29,4 +29,4 @@
     TrackingParametersFeatureName("trackingParameters"),
 }
 
-const val PRIVACY_REMOTE_CONFIG_URL = "https://staticcdn.duckduckgo.com/trackerblocking/config/v5/android-config.json"
+const val PRIVACY_REMOTE_CONFIG_URL = "https://duckduckgo.github.io/privacy-configuration/pr-5175/v4/android-config.json"

UI changes

n/a


Note

Medium Risk
Injects dynamically-sourced JavaScript into WebView on page start; mistakes could impact page behavior/performance or unintentionally run on the wrong domains, though it’s gated by feature toggles and domain checks.

Overview
Adds a new JsInjectorPlugin that, on onPageStarted, conditionally injects ad-blocking “scriptlets” into YouTube pages (youtube.com / youtube-nocookie.com and subdomains) via evaluateJavascript.

Introduces a AdBlockingStatusChecker gate (kill-switch + contingency-mode toggle) and extends AdBlockingExtensionRepository with a scriptletsFlow() so the injector can use the latest stored scriptlets, plus unit tests covering gating, domain matching, ordering, and update behavior.

Reviewed by Cursor Bugbot for commit ca5bcf7. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown
Collaborator Author

CrisBarreiro commented May 19, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces the core plumbing to inject “ad blocking extension” scriptlets into pages (currently targeting YouTube domains), sourcing the scriptlet payload from the local Room store and gating injection behind feature toggles.

Changes:

  • Add AdBlockingExtensionJsInjectorPlugin to build and inject a combined JS payload on onPageStarted.
  • Extend AdBlockingExtensionRepository with a scriptletsFlow() API and introduce a Scriptlet model.
  • Add tests for injection gating (feature flags, domain matching) and payload behavior (sorting, updates); add AndroidX.core.ktx dependency for toUri.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ad-blocking/ad-blocking-impl/src/main/java/com/duckduckgo/adblocking/impl/AdBlockingExtensionJsInjectorPlugin.kt New JS injector plugin that gates and injects scriptlets on page start for configured domains.
ad-blocking/ad-blocking-impl/src/main/java/com/duckduckgo/adblocking/impl/AdBlockingExtensionRepository.kt Adds a flow-based API to observe scriptlets and maps DB entities into Scriptlet.
ad-blocking/ad-blocking-impl/src/main/java/com/duckduckgo/adblocking/impl/Scriptlet.kt Introduces a Scriptlet data model (name + JS content).
ad-blocking/ad-blocking-impl/src/test/java/com/duckduckgo/adblocking/impl/AdBlockingExtensionJsInjectorPluginTest.kt Adds unit tests covering injection conditions and payload composition.
ad-blocking/ad-blocking-impl/build.gradle Adds AndroidX.core.ktx dependency required by the plugin.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@CrisBarreiro CrisBarreiro force-pushed the feature/cris/ad-blocking/download-store-scriptlets branch from 3b6160c to f23bf2f Compare May 21, 2026 10:41
@CrisBarreiro CrisBarreiro force-pushed the feature/cris/ad-blocking/core-ad-blocking branch from ca28c5a to e3ccd58 Compare May 21, 2026 10:41
Copy link
Copy Markdown
Contributor

@cmonfortep cmonfortep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I need to test on a real device, but not blocker. When testing this on the emulators I noticed few seconds of loading on every video, I don't remember seeing that when I did the hackphase. if we see this happening, when we are doing pixels, we should check if we have something we can use to track this.

?.sortedBy { it.name }
?.joinToString(separator = "\n") { it.content }

private val domains = listOf(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this expected to be local list or provided from the remote config?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, expected to be local. Discussed over zoom

Copy link
Copy Markdown
Contributor

@cmonfortep cmonfortep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@CrisBarreiro CrisBarreiro force-pushed the feature/cris/ad-blocking/core-ad-blocking branch from e241c58 to 71544f4 Compare May 22, 2026 07:41
@CrisBarreiro CrisBarreiro force-pushed the feature/cris/ad-blocking/download-store-scriptlets branch from f23bf2f to 5142d91 Compare May 22, 2026 07:41
@CrisBarreiro CrisBarreiro force-pushed the feature/cris/ad-blocking/core-ad-blocking branch from 71544f4 to e4d29da Compare May 22, 2026 08:12
@CrisBarreiro CrisBarreiro force-pushed the feature/cris/ad-blocking/download-store-scriptlets branch from 5142d91 to 8a3a2a0 Compare May 22, 2026 08:12
@CrisBarreiro CrisBarreiro force-pushed the feature/cris/ad-blocking/core-ad-blocking branch from e4d29da to ca5bcf7 Compare May 22, 2026 10:29
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.

3 participants