mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 22:01:41 +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 `
|
return `
|
||||||
window.__completionCallbacks = [];
|
window.__completionCallbacks = [];
|
||||||
// Check if we're in an extension context by examining the URL
|
// 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 = () => {
|
window.__isExtensionContext = () => {
|
||||||
const url = window.location.href;
|
const url = window.location.href;
|
||||||
return url.startsWith('chrome-extension://') ||
|
return !(url.startsWith('http://') ||
|
||||||
url.startsWith('moz-extension://') ||
|
url.startsWith('https://') ||
|
||||||
url === 'about:srcdoc';
|
url.startsWith('file://'));
|
||||||
};
|
};
|
||||||
window.sendRuntimeMessage = async (message) => {
|
window.sendRuntimeMessage = async (message) => {
|
||||||
const messageId = 'msg_' + Date.now() + '_' + Math.random().toString(36).substring(2, 9);
|
const messageId = 'msg_' + Date.now() + '_' + Math.random().toString(36).substring(2, 9);
|
||||||
|
|
@ -76,11 +77,12 @@ window.onCompleted = (callback) => {
|
||||||
return `
|
return `
|
||||||
window.__completionCallbacks = [];
|
window.__completionCallbacks = [];
|
||||||
// Check if we're in an extension context by examining the URL
|
// 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 = () => {
|
window.__isExtensionContext = () => {
|
||||||
const url = window.location.href;
|
const url = window.location.href;
|
||||||
return url.startsWith('chrome-extension://') ||
|
return !(url.startsWith('http://') ||
|
||||||
url.startsWith('moz-extension://') ||
|
url.startsWith('https://') ||
|
||||||
url === 'about:srcdoc';
|
url.startsWith('file://'));
|
||||||
};
|
};
|
||||||
window.sendRuntimeMessage = async (message) => {
|
window.sendRuntimeMessage = async (message) => {
|
||||||
return await chrome.runtime.sendMessage({
|
return await chrome.runtime.sendMessage({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue