feat: Migrate to Chrome Manifest V3 with Hybrid DeclarativeNetRequest Engine - #532
Open
OmarAlaaeldein wants to merge 3 commits into
Open
feat: Migrate to Chrome Manifest V3 with Hybrid DeclarativeNetRequest Engine#532OmarAlaaeldein wants to merge 3 commits into
OmarAlaaeldein wants to merge 3 commits into
Conversation
|
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.



feat: Migrate to Chrome Manifest V3 with Hybrid DeclarativeNetRequest Engine
Context
With Google Chrome officially phasing out Manifest V2, this Merge Request updates ClearURLs to fully support the Manifest V3 architecture, securing its future on Chrome-based browsers.
This PR is a comprehensive architectural upgrade that preserves the core logic and manual functionalities of the extension while fully complying with Manifest V3 restrictions (Service Workers, DeclarativeNetRequest, and strict Content Security Policies).
Major Architectural Changes
1. Hybrid
declarativeNetRequestEngine (clearurls.js)Since the synchronous
webRequestBlockingAPI has been deprecated, the core filtering engine has been rebuilt into a hybrid model:declarativeNetRequest(DNR) rules.redirect+queryTransform.removeParams.block.regexSubstitutionwith capture groups.regexFilterexceeding 2KB in memory. Rather than allowing a single oversized exception regex to fail the entire rule payload, we now runchrome.declarativeNetRequest.isRegexSupported()on every regex rule first. Unsupported/oversized rules are gracefully skipped.Providerclasses and parsing logic remain completely intact so that the manual Context Menu cleaning, History Listener, and UI Cleaning Tool still function exactly as before.2. Service Worker Lifecycle (
background.js&storage.js)Background scripts have been replaced by an ephemeral Service Worker.
background.jsas the sole entry point, which usesimportScripts()to load all dependencies in the correct order.deferSaveOnDiskfrom a 30-second timeout down to 5 seconds to ensure data is safely persisted before Chrome aggressively terminates the Service Worker.genesis()and addedensureStorageLoaded()to protect against cold-starts.setIntervalwatchdog operations tochrome.alarmsto ensure they trigger reliably outside of active memory.3. Content Scripts & Strict CSP (
manifest.json)Manifest V3's strict Content Security Policy (
script-src 'self') bans the inline<script>injections previously used to hijackwindow.rwtandwindow._borschik."world": "MAIN"to the Google and Yandex content scripts inmanifest.json. This securely executes the content script directly within the webpage's DOM context, allowing us to hookwindowproperties natively without injecting custom DOM elements.4. API Modernization & Security
window[request.function].apply()). Background messaging is now strictly routed through an explicitmessageHandlersdispatch map.Object.prototype.getOrDefault. It is now a standalone utility function, preventing conflicts with third-party libraries (like jQuery/DataTables).browser.tabs.executeScriptwith the modernchrome.scripting.executeScript(using the{func: myFunc, args: [...]}pattern to serialize payloads and neutralize XSS).browser.browserActioncommands tobrowser.action.eTagFilter.jsnow removes ETags completely using a DNRmodifyHeadersrule (reserved ID: 99999), as synchronous header modification is no longer permitted.Testing Performed
declarativeNetRequestrules compile and install correctly (bypassing the 2KB limit).chrome.scripting.(Note: Automated CI pipeline checks only include JSON minification and hash generation; no unit tests were present to run)