Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { IframeHTMLAttributes } from 'react';
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
import { observer } from 'mobx-react-lite';
import { connect, WindowMessenger } from 'penpal';
import { PreloadScriptState } from '@/components/store/editor/sandbox';

import type { Frame } from '@onlook/models';
import type {
Expand Down Expand Up @@ -86,6 +87,12 @@ export const FrameComponent = observer(

const setupPenpalConnection = () => {
try {
const sandbox = editorEngine.activeSandbox;
if (sandbox?.preloadScriptState === PreloadScriptState.LOADING) {
console.log(`${PENPAL_PARENT_CHANNEL} (${frame.id}) - Preload script still loading, will retry on next load`);
return;
}

if (!iframeRef.current?.contentWindow) {
console.error(`${PENPAL_PARENT_CHANNEL} (${frame.id}) - No iframe found`);
onConnectionFailed();
Expand Down
26 changes: 17 additions & 9 deletions apps/web/client/src/components/store/editor/sandbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class SandboxManager {
readonly gitManager: GitManager;
private providerReactionDisposer?: () => void;
private sync: CodeProviderSync | null = null;
private preloadRetryTimeoutId?: ReturnType<typeof setTimeout>;
preloadScriptState: PreloadScriptState = PreloadScriptState.NOT_INJECTED
routerConfig: RouterConfig | null = null;

Expand Down Expand Up @@ -110,9 +111,13 @@ export class SandboxManager {
this.preloadScriptState = PreloadScriptState.INJECTED
} catch (error) {
console.error('[SandboxManager] Failed to ensure preload script exists:', error);
// Mark as injected to prevent blocking frames indefinitely
// Frames will handle the missing preload script gracefully
this.preloadScriptState = PreloadScriptState.NOT_INJECTED
this.preloadScriptState = PreloadScriptState.NOT_INJECTED;
this.preloadRetryTimeoutId = setTimeout(() => {
if (this.preloadScriptState === PreloadScriptState.NOT_INJECTED) {
console.log('[SandboxManager] Retrying preload script injection...');
void this.ensurePreloadScriptExists();
}
}, 3000);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}

Expand Down Expand Up @@ -214,11 +219,14 @@ export class SandboxManager {
}

clear() {
this.providerReactionDisposer?.();
this.providerReactionDisposer = undefined;
this.sync?.release();
this.sync = null;
this.preloadScriptState = PreloadScriptState.NOT_INJECTED
this.session.clear();
if (this.preloadRetryTimeoutId) {
clearTimeout(this.preloadRetryTimeoutId);
this.preloadRetryTimeoutId = undefined;
}
this.providerReactionDisposer = undefined;
this.sync?.release();
this.sync = null;
this.preloadScriptState = PreloadScriptState.NOT_INJECTED
this.session.clear();
}
}
11 changes: 6 additions & 5 deletions apps/web/client/src/server/api/routers/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ export const projectRouter = createTRPCRouter({
const url = getSandboxPreviewUrl(branch.sandboxId, port);
const app = new FirecrawlApp({ apiKey: env.FIRECRAWL_API_KEY });

// Optional: Add actions to click the button for CSB free tier
// const _csbFreeActions = [{
// type: 'click',
// selector: '#btn-answer-yes',
// }];
const csbFreeActions = [{
type: 'click',
selector: '#btn-answer-yes',
}];

const result = await app.scrapeUrl(url, {
formats: ['screenshot'],
onlyMainContent: true,
timeout: 10000,
actions: csbFreeActions,
});

if (!result.success) {
Expand Down