Revert: Fix extension context detection - original logic was correct

The negated approach broke browser_script which runs in page context.
browser_script injects into web pages (http://, https://) where
chrome.runtime.sendMessage doesn't work. The original whitelist
approach correctly identifies extension contexts only.

The real issue with artifacts in sandbox iframes needs a different fix.
This commit is contained in:
Mario Zechner 2025-10-11 19:32:33 +02:00
parent 372be18657
commit 8a96741441
2 changed files with 60 additions and 28 deletions

View file

@ -29,12 +29,11 @@ export class RuntimeMessageBridge {
return `
window.__completionCallbacks = [];
// Check if we're in an extension context by examining the URL
// We check for web/file protocols and negate - anything else is extension context
window.__isExtensionContext = () => {
const url = window.location.href;
return !(url.startsWith('http://') ||
url.startsWith('https://') ||
url.startsWith('file://'));
return url.startsWith('chrome-extension://') ||
url.startsWith('moz-extension://') ||
url === 'about:srcdoc';
};
window.sendRuntimeMessage = async (message) => {
const messageId = 'msg_' + Date.now() + '_' + Math.random().toString(36).substring(2, 9);
@ -77,12 +76,11 @@ window.onCompleted = (callback) => {
return `
window.__completionCallbacks = [];
// Check if we're in an extension context by examining the URL
// We check for web/file protocols and negate - anything else is extension context
window.__isExtensionContext = () => {
const url = window.location.href;
return !(url.startsWith('http://') ||
url.startsWith('https://') ||
url.startsWith('file://'));
return url.startsWith('chrome-extension://') ||
url.startsWith('moz-extension://') ||
url === 'about:srcdoc';
};
window.sendRuntimeMessage = async (message) => {
return await chrome.runtime.sendMessage({