Skip to content

Commit

Permalink
Fix Chromium MV3 extension
Browse files Browse the repository at this point in the history
Chromium MV2 used `onBeforeRequest`, which was not replicated for `MV3`.
This commit addresses this issue.

In addition, cached initiator URL takes precedence over details provided
initiator, which might not reflect the main frame domain.
  • Loading branch information
thibmeu committed Nov 7, 2023
1 parent c0aefd7 commit eecf7ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions platform/mv3/chromium/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
BROWSERS,
handleBeforeRequest,
handleBeforeSendHeaders,
handleHeadersReceived,
handleInstall,
Expand All @@ -10,6 +11,8 @@ const STORAGE = chrome.storage.local;

chrome.runtime.onInstalled.addListener(handleInstall(STORAGE));

chrome.webRequest.onBeforeRequest.addListener(handleBeforeRequest(), { urls: ['<all_urls>'] });

chrome.webRequest.onBeforeSendHeaders.addListener(
handleBeforeSendHeaders(STORAGE),
{ urls: ['<all_urls>'] },
Expand Down
4 changes: 2 additions & 2 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ export const handleHeadersReceived =
initiator = details.url;
} else {
initiator =
details.initiator ??
details.frameAncestors?.at(0)?.url ??
cachedTabs[details.tabId]?.url;
cachedTabs[details.tabId]?.url ??
details.initiator;
}
if (!initiator) {
return;
Expand Down

0 comments on commit eecf7ea

Please sign in to comment.