From 6ffffb7b2bb1386bb3fe97caa06baec729dc07de Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 31 Mar 2025 16:30:17 -0400 Subject: [PATCH] [mv3] Force real origin in `postMessage` so that `use_dynamic_url` can be used Call to postMessage was failing in the zapper when using `use_dynamic_url` in manifest. Manually overwriting the per-session dynamic hostname with the real extension id fixes this. --- platform/mv3/chromium/manifest.json | 3 ++- platform/mv3/extension/js/scripting/zapper.js | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/platform/mv3/chromium/manifest.json b/platform/mv3/chromium/manifest.json index a5ff0306f..d913bf1f6 100644 --- a/platform/mv3/chromium/manifest.json +++ b/platform/mv3/chromium/manifest.json @@ -63,7 +63,8 @@ ], "matches": [ "" - ] + ], + "use_dynamic_url": true } ] } diff --git a/platform/mv3/extension/js/scripting/zapper.js b/platform/mv3/extension/js/scripting/zapper.js index 038ea1601..fb37ee1cf 100644 --- a/platform/mv3/extension/js/scripting/zapper.js +++ b/platform/mv3/extension/js/scripting/zapper.js @@ -365,7 +365,7 @@ const onFrameMessage = function(msg) { // can remove the iframe. const bootstrap = async ( ) => { - const url = new URL(chrome.runtime.getURL('/zapper-ui.html')); + const dynamicURL = new URL(chrome.runtime.getURL('/zapper-ui.html')); return new Promise(resolve => { const frame = document.createElement('iframe'); frame.setAttribute(zapperSecret, ''); @@ -381,9 +381,11 @@ const bootstrap = async ( ) => { port.onmessageerror = ( ) => { quitZapper(); }; + const realURL = new URL(dynamicURL); + realURL.hostname = chrome.i18n.getMessage('@@extension_id'); frame.contentWindow.postMessage( { what: 'zapperStart' }, - url.origin, + realURL.origin, [ channel.port2 ] ); frame.contentWindow.focus(); @@ -392,7 +394,7 @@ const bootstrap = async ( ) => { zapperFramePort: port, }); }; - frame.contentWindow.location = url.href; + frame.contentWindow.location = dynamicURL.href; }); };