Skip to content

fix: improve Chrome MV3 compatibility for latest versions - #771

Open
dalishenying-cloud wants to merge 1 commit into
tarampampam:masterfrom
dalishenying-cloud:fix/chrome-mv3-compat
Open

fix: improve Chrome MV3 compatibility for latest versions#771
dalishenying-cloud wants to merge 1 commit into
tarampampam:masterfrom
dalishenying-cloud:fix/chrome-mv3-compat

Conversation

@dalishenying-cloud

Copy link
Copy Markdown

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

  • All 910 existing tests pass
  • TypeScript compilation succeeds

- 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
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.

1 participant