mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 21:03:42 +00:00
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:
parent
98ea763d64
commit
372be18657
1 changed files with 8 additions and 6 deletions
|
|
@ -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({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue