Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(editor): a tool call that lands during a subframe load no longer waits forever

esenginea0263fe4a6ea
diff --git a/desktop/electron/surfaceDriver.ts b/desktop/electron/surfaceDriver.ts
index 6fb18a5aa..fdc99a670 100644
--- a/desktop/electron/surfaceDriver.ts
+++ b/desktop/electron/surfaceDriver.ts
@@ -62,8 +62,14 @@ export function createSurfaceDriver(getWin: () => BrowserWindow | null): Surface
const win = requireWin();
// A call can arrive before the renderer finished booting (the endpoint comes
// up with the window) — wait out the initial load instead of failing it.
- if (win.webContents.isLoading()) {
- await new Promise<void>((resolve) => win.webContents.once('did-finish-load', () => resolve()));
+ // Polled, never event-awaited: isLoading() covers SUBFRAMES (the play realm
+ // prewarms in an iframe seconds after a project opens), but did-finish-load
+ // fires only for the main frame — a call that awaited the event during a
+ // subframe load parked forever, timing out whichever automation call drew
+ // the short straw. Bounded: a page that never settles still gets the call,
+ // and executeJavaScript's own error is a better answer than silence.
+ for (let waited = 0; win.webContents.isLoading() && waited < 10_000; waited += 50) {
+ await new Promise((r) => setTimeout(r, 50));
}
return unwrap(await win.webContents.executeJavaScript(carryError(code), true));
};