From 3bb4ab4a46cce12b4d82ae9298ba3a90b3b68088 Mon Sep 17 00:00:00 2001 From: Jan-Felix Date: Thu, 19 Sep 2024 17:42:29 +0200 Subject: [PATCH] prevent error in packed mode --- extension/src/background.ts | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/extension/src/background.ts b/extension/src/background.ts index a6c2cede..ef41c288 100644 --- a/extension/src/background.ts +++ b/extension/src/background.ts @@ -6,15 +6,18 @@ interface Fork { rpcUrl: string } -chrome.declarativeNetRequest.onRuleMatchedDebug.addListener((details) => { - if (details.rule.ruleId !== HEADERS_RULE_ID) { - console.debug( - 'rule matched on request', - details.request.url, - details.rule.ruleId - ) - } -}) +// The chrome.declarativeNetRequest.onRuleMatchedDebug is only available for unpacked extensions. +if (chrome.declarativeNetRequest.onRuleMatchedDebug) { + chrome.declarativeNetRequest.onRuleMatchedDebug.addListener((details) => { + if (details.rule.ruleId !== HEADERS_RULE_ID) { + console.debug( + 'rule matched on request', + details.request.url, + details.rule.ruleId + ) + } + }) +} // Track tabs showing our extension, so we can dynamically adjust the declarativeNetRequest rule. // This rule removes some headers so foreign pages can be loaded in iframes. We don't want to @@ -128,12 +131,6 @@ const toggle = async (tab: chrome.tabs.Tab) => { chrome.action.onClicked.addListener(toggle) -// wake up the background script after chrome restarts -// this fixes an issue of the action onClicked listener not being triggered (see: https://stackoverflow.com/a/76344225) -chrome.runtime.onStartup.addListener(() => { - console.debug(`Zodiac Pilot startup`) -}) - // Track extension tabs that are actively simulating, meaning that RPC requests are being sent to // a fork network. const simulatingExtensionTabs = new Map() @@ -291,6 +288,7 @@ const networkIdOfRpcUrlPromisePerTab = new Map< number, Map> >() + chrome.webRequest.onBeforeRequest.addListener( (details: chrome.webRequest.WebRequestBodyDetails) => { // only consider requests from extension tabs