Skip to content

Commit a454360

Browse files
committed
fix(engine): probe HeadlessExperimental.beginFrame, not just .enable
First version of the probe only called `HeadlessExperimental.enable`, but some Chromium builds keep the domain registered (so enable() succeeds) and drop the beginFrame method itself. The warmup loop then crashes on first frame with `'HeadlessExperimental.beginFrame' wasn't found` — exactly the failure mode reported in heygen-com#294. Race one cheap beginFrame call against a 2s timeout. Any failure — method missing, timeout, generic protocol error — is treated as unsupported and the caller relaunches in screenshot mode. Verified against chrome-headless- shell 146 on Linux x86_64 (real beginFrame support, probe returns true) and forced-fail mode (probe returns false → strip beginframe flags → relaunch → valid 6.8 KB PNG captured). Found via devbox testing heygen-com#294 repro on Linux.
1 parent 07901ce commit a454360

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

‎packages/engine/src/services/browserManager.ts‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,37 @@ function stripBeginFrameFlags(args: string[]): string[] {
9999

100100
/**
101101
* Probe whether the browser still speaks HeadlessExperimental.beginFrame.
102-
* Chromium 132+ removed the domain; calling enable() on a fresh page throws
103-
* "'HeadlessExperimental.enable' wasn't found". Returns true if supported.
102+
*
103+
* Some Chromium builds keep the domain registered (HeadlessExperimental.enable
104+
* succeeds) but drop the beginFrame method itself — in that case the capture
105+
* loop dies on first frame with `'HeadlessExperimental.beginFrame' wasn't
106+
* found`. So we probe BOTH: enable + one cheap beginFrame. The beginFrame is
107+
* raced against a 2s timeout because in beginframe-control mode the command
108+
* completes as soon as the compositor acks — no network or GPU work involved.
109+
*
110+
* Any failure (method missing, timeout, protocol error) is treated as
111+
* unsupported. Real errors after launch would surface in the warmup loop and
112+
* fall out through the caller's try/catch.
104113
*/
105114
async function probeBeginFrameSupport(browser: Browser): Promise<boolean> {
106115
let page;
107116
try {
108117
page = await browser.newPage();
109118
const client = await page.createCDPSession();
110119
await client.send("HeadlessExperimental.enable");
120+
const beginFrame = client.send("HeadlessExperimental.beginFrame", {
121+
frameTimeTicks: 0,
122+
interval: 33,
123+
noDisplayUpdates: true,
124+
});
125+
const timeout = new Promise<never>((_, reject) =>
126+
setTimeout(() => reject(new Error("beginFrame probe timeout")), 2000),
127+
);
128+
await Promise.race([beginFrame, timeout]);
111129
await client.detach().catch(() => {});
112130
return true;
113-
} catch (err) {
114-
const msg = err instanceof Error ? err.message : String(err);
115-
if (/HeadlessExperimental\b.*(wasn't found|not found|not enabled)/i.test(msg)) {
116-
return false;
117-
}
118-
throw err;
131+
} catch {
132+
return false;
119133
} finally {
120134
await page?.close().catch(() => {});
121135
}

0 commit comments

Comments
 (0)