From 6a7c264ab2a362f2347ddf9bfab4ce737535c367 Mon Sep 17 00:00:00 2001 From: Jan-Felix Date: Thu, 19 Sep 2024 12:46:08 +0200 Subject: [PATCH 1/2] enable safe apps bridge for nexus mutual --- extension/src/bridge/SafeAppBridge.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/extension/src/bridge/SafeAppBridge.ts b/extension/src/bridge/SafeAppBridge.ts index 02f599ed..4fd43a41 100644 --- a/extension/src/bridge/SafeAppBridge.ts +++ b/extension/src/bridge/SafeAppBridge.ts @@ -49,6 +49,7 @@ export const SAFE_APP_WHITELIST = [ 'https://curve.fi', 'https://app.spark.fi', 'https://community.safe.global', + 'https://app.nexusmutual.io', ] export default class SafeAppBridge { From cb9f1aeae91e6e0d2e0addc9de6de92b4d00224b Mon Sep 17 00:00:00 2001 From: Jan-Felix Date: Thu, 19 Sep 2024 12:56:33 +0200 Subject: [PATCH 2/2] trial to fix service worker initialization in packed installs --- extension/src/background.ts | 107 ++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/extension/src/background.ts b/extension/src/background.ts index b9e5cb96..cfc45f6d 100644 --- a/extension/src/background.ts +++ b/extension/src/background.ts @@ -6,16 +6,6 @@ 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 - ) - } -}) - // 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 // generally circumvent this security mechanism, so we only apply it to extension tabs. @@ -125,7 +115,6 @@ const toggle = async (tab: chrome.tabs.Tab) => { }) } } -chrome.action.onClicked.addListener(toggle) // Track extension tabs that are actively simulating, meaning that RPC requests are being sent to // a fork network. @@ -246,35 +235,6 @@ const removeRpcRedirectRules = (tabId: number) => { console.log('removed all RPC redirect rules for tab', tabId, ruleIds) } -chrome.runtime.onMessage.addListener((message, sender) => { - if (!sender.tab?.id) return - - if (message.type === 'startSimulating') { - const { networkId, rpcUrl } = message - simulatingExtensionTabs.delete(sender.tab.id) - removeRpcRedirectRules(sender.tab.id) - simulatingExtensionTabs.set(sender.tab.id, { - networkId, - rpcUrl, - }) - updateRpcRedirectRules(sender.tab.id) - - console.debug( - `start intercepting JSON RPC requests for network #${networkId} in tab #${sender.tab.id}`, - rpcUrl - ) - } - - if (message.type === 'stopSimulating') { - simulatingExtensionTabs.delete(sender.tab.id) - removeRpcRedirectRules(sender.tab.id) - - console.debug( - `stop intercepting JSON RPC requests in tab #${sender.tab.id}` - ) - } -}) - // Keep track of the network IDs for all JSON RPC endpoints used from apps in the Pilot frame const networkIdOfRpcUrlPerTab = new Map< number, @@ -361,20 +321,63 @@ const getJsonRpcBody = (details: chrome.webRequest.WebRequestBodyDetails) => { return json } -chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { - const isExtensionTab = !!tab.url?.startsWith(PILOT_URL) - const wasExtensionTab = activeExtensionTabs.has(tabId) +chrome.runtime.onInstalled.addListener(() => { + chrome.action.onClicked.addListener(toggle) - if (isExtensionTab && !wasExtensionTab) { - startTrackingTab(tabId) - } - if (!isExtensionTab && wasExtensionTab) { - stopTrackingTab(tabId) - } + chrome.declarativeNetRequest.onRuleMatchedDebug.addListener((details) => { + if (details.rule.ruleId !== HEADERS_RULE_ID) { + console.debug( + 'rule matched on request', + details.request.url, + details.rule.ruleId + ) + } + }) - if (changeInfo.status === 'complete' && isExtensionTab) { - chrome.tabs.sendMessage(tabId, { type: 'navigationDetected' }) - } + chrome.runtime.onMessage.addListener((message, sender) => { + if (!sender.tab?.id) return + + if (message.type === 'startSimulating') { + const { networkId, rpcUrl } = message + simulatingExtensionTabs.delete(sender.tab.id) + removeRpcRedirectRules(sender.tab.id) + simulatingExtensionTabs.set(sender.tab.id, { + networkId, + rpcUrl, + }) + updateRpcRedirectRules(sender.tab.id) + + console.debug( + `start intercepting JSON RPC requests for network #${networkId} in tab #${sender.tab.id}`, + rpcUrl + ) + } + + if (message.type === 'stopSimulating') { + simulatingExtensionTabs.delete(sender.tab.id) + removeRpcRedirectRules(sender.tab.id) + + console.debug( + `stop intercepting JSON RPC requests in tab #${sender.tab.id}` + ) + } + }) + + chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { + const isExtensionTab = !!tab.url?.startsWith(PILOT_URL) + const wasExtensionTab = activeExtensionTabs.has(tabId) + + if (isExtensionTab && !wasExtensionTab) { + startTrackingTab(tabId) + } + if (!isExtensionTab && wasExtensionTab) { + stopTrackingTab(tabId) + } + + if (changeInfo.status === 'complete' && isExtensionTab) { + chrome.tabs.sendMessage(tabId, { type: 'navigationDetected' }) + } + }) }) export {}