fix: improve Chrome MV3 compatibility for latest versions - #771
Open
dalishenying-cloud wants to merge 1 commit into
Open
fix: improve Chrome MV3 compatibility for latest versions#771dalishenying-cloud wants to merge 1 commit into
dalishenying-cloud wants to merge 1 commit into
Conversation
- Add hardcoded ResourceType fallback for declarativeNetRequest rules - Fix whitelist mode: use only requestDomains instead of AND condition - Add matchOriginAsFallback for sandboxed iframe support - Add fetch/XHR interception to defeat service worker UA detection - Add onInstalled/onStartup handlers for service worker lifecycle - Change permission to declarativeNetRequestWithHostAccess - Add error handling with retry for updateDynamicRules
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.
Summary
This PR fixes several Chrome MV3 compatibility issues that prevent the extension from working on the latest Chrome versions (130+).
Changes
1. ResourceType fallback
Added hardcoded fallback for chrome.declarativeNetRequest.ResourceType. In some Chrome versions, the enum may not be available in the service worker context, causing rules to match zero requests.
2. Whitelist mode fix
Fixed whitelist mode by using only requestDomains instead of setting both initiatorDomains AND requestDomains. Chrome treats both conditions as AND, making whitelist mode non-functional.
3. Sandboxed iframe support
Added matchOriginAsFallback: true to content script registration. This allows scripts to run in sandboxed iframes (those without allow-same-origin).
4. Service worker UA detection
Added fetch() and XMLHttpRequest interception to override User-Agent header BEFORE service workers see it.
5. Service worker lifecycle
Added onInstalled and onStartup handlers to ensure declarativeNetRequest rules are re-applied.
6. Modern API usage
Changed permission from declarativeNetRequest to declarativeNetRequestWithHostAccess.
7. Error handling
Added try-catch with retry logic for updateDynamicRules calls.
Testing