Fix module script validation and extension context detection

1. Skip JavaScript validation for <script type="module"> tags
   - new Function() cannot validate ES module syntax (import/export)
   - Module scripts now execute without validation errors
   - Fixes issue where HTML artifacts with modules would fail to load

2. Improve __isExtensionContext detection logic
   - Changed from whitelist (chrome-extension://, moz-extension://)
   - To blacklist approach: negate http://, https://, file://
   - More robust - handles all extension protocols (about:srcdoc, etc.)
   - Fixes "offline mode" errors when using browser_script artifacts

Resolves artifacts not working in extension context after document.write()
This commit is contained in:
Mario Zechner 2025-10-11 19:19:19 +02:00
parent 98ea763d64
commit 372be18657

View file

@ -29,11 +29,12 @@ 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('chrome-extension://') ||
url.startsWith('moz-extension://') ||
url === 'about:srcdoc';
return !(url.startsWith('http://') ||
url.startsWith('https://') ||
url.startsWith('file://'));
};
window.sendRuntimeMessage = async (message) => {
const messageId = 'msg_' + Date.now() + '_' + Math.random().toString(36).substring(2, 9);
@ -76,11 +77,12 @@ 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('chrome-extension://') ||
url.startsWith('moz-extension://') ||
url === 'about:srcdoc';
return !(url.startsWith('http://') ||
url.startsWith('https://') ||
url.startsWith('file://'));
};
window.sendRuntimeMessage = async (message) => {
return await chrome.runtime.sendMessage({