[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.
This commit is contained in:
Raymond Hill 2025-03-31 16:30:17 -04:00
parent 0c6cbb7fcb
commit 6ffffb7b2b
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
2 changed files with 7 additions and 4 deletions

View file

@ -63,7 +63,8 @@
],
"matches": [
"<all_urls>"
]
],
"use_dynamic_url": true
}
]
}

View file

@ -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;
});
};