mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 16:00:58 +00:00
Fix extension context detection in runtime providers
Replace window.sendRuntimeMessage existence check with URL-based detection. The sendRuntimeMessage function exists in both extension and non-extension contexts (e.g., downloaded HTML artifacts), causing incorrect behavior. Changes: - Add window.__isExtensionContext() helper to RuntimeMessageBridge that checks: - chrome-extension:// URLs (Chrome) - moz-extension:// URLs (Firefox) - about:srcdoc (sandbox iframes) - Update all runtime providers to use __isExtensionContext() instead: - FileDownloadRuntimeProvider: Correctly falls back to browser download - ConsoleRuntimeProvider: Only sends messages in extension context - ArtifactsRuntimeProvider: Properly detects offline/read-only mode This fixes the issue where downloaded HTML artifacts incorrectly try to communicate with the extension when opened from disk.
This commit is contained in:
parent
46c1da9826
commit
b5648eaabd
4 changed files with 23 additions and 9 deletions
|
|
@ -51,8 +51,8 @@ export class ConsoleRuntimeProvider implements SandboxRuntimeProvider {
|
|||
// Always log locally too
|
||||
(originalConsole as any)[method].apply(console, args);
|
||||
|
||||
// Send immediately and track the promise
|
||||
if ((window as any).sendRuntimeMessage) {
|
||||
// Send immediately and track the promise (only in extension context)
|
||||
if ((window as any).__isExtensionContext?.()) {
|
||||
const sendPromise = (window as any)
|
||||
.sendRuntimeMessage({
|
||||
type: "console",
|
||||
|
|
@ -108,7 +108,7 @@ export class ConsoleRuntimeProvider implements SandboxRuntimeProvider {
|
|||
|
||||
const finalError = error || lastError;
|
||||
|
||||
if ((window as any).sendRuntimeMessage) {
|
||||
if ((window as any).__isExtensionContext?.()) {
|
||||
if (finalError) {
|
||||
await (window as any).sendRuntimeMessage({
|
||||
type: "execution-error",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue