{"record":{"id":"9576c5faff03b57f","repo":"chenglou/pretext","slug":"tree-message-tree-error","errorCode":null,"errorMessage":"${tree.message ?? tree.error}","messagePattern":"\\$\\{tree\\.message \\?\\? tree\\.error\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/browser-automation.ts","lineNumber":386,"sourceCode":"  ], {\n    cwd: process.cwd(),\n    stdio: 'ignore',\n  })\n\n  let bidi: FirefoxBidiClient | null = null\n\n  try {\n    await waitForPort(bidiPort)\n    bidi = await connectFirefoxBidi(bidiPort)\n\n    const session = await bidi.send('session.new', { capabilities: { alwaysMatch: {} } })\n    if (session.error !== undefined) {\n      throw new Error(session.message ?? session.error)\n    }\n\n    const tree = await bidi.send('browsingContext.getTree', {})\n    if (tree.error !== undefined) {\n      throw new Error(tree.message ?? tree.error)\n    }\n\n    const contexts = (tree.result as { contexts: Array<{ context: string }> }).contexts\n    const context = contexts[0]?.context\n    if (context === undefined) {\n      throw new Error('Firefox BiDi returned no browsing context')\n    }\n\n    return {\n      bidi,\n      context,\n      firefoxProcess,\n      profileDir,\n    }\n  } catch (error) {\n    bidi?.close()\n    try {\n      firefoxProcess.kill('SIGTERM')","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/chenglou/pretext/blob/ac49b09b7d83ede19581fa94a8b892b07d309baf/scripts/browser-automation.ts#L368-L404","documentation":"Thrown during Firefox session initialization when the WebDriver BiDi 'browsingContext.getTree' command returns an error. This call happens after session.new succeeded (error 16 did not fire), so the BiDi session is valid but listing browsing contexts failed. The thrown message uses tree.message if present, else tree.error.","triggerScenarios":"session.new succeeded but browsingContext.getTree returned an error — transient BiDi state, a Firefox internal error enumerating contexts, or the about:blank context not yet ready when the call landed. Rare relative to error 16.","commonSituations":"Timing race where the context tree is queried before Firefox finishes setting up the initial about:blank tab; a Firefox BiDi implementation bug on the installed version; intermittent BiDi protocol error under load.","solutions":["Re-run — transient BiDi errors during context enumeration often clear on retry.","Upgrade Firefox to a version with stable browsingContext.getTree support.","If reproducible, add a short retry loop around getTree in initializeFirefoxSession (the current code calls it once).","Launch Firefox manually with the same flags to see if getTree fails interactively."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"function isBidiTreeError(tree: { error?: unknown, message?: unknown }): boolean {\n  return tree.error !== undefined\n}","tryCatchPattern":"// Retry browsingContext.getTree a few times for transient enumeration errors.\nlet tree\nfor (let i = 0; i < 3; i++) {\n  tree = await bidi.send('browsingContext.getTree', {})\n  if (tree.error === undefined) break\n  await sleep(250)\n}\nif (tree.error !== undefined) throw new Error(tree.message ?? tree.error)","preventionTips":["Treat a single getTree error as transient; retry before giving up.","Keep Firefox updated to reduce BiDi protocol instability.","If reproducible, file/report the BiDi regression against the installed Firefox version."],"tags":["browser-automation","firefox","webdriver-bidi","transient","browsing-context"],"backgroundTag":null,"analyzedSha":"ac49b09b7d83ede19581fa94a8b892b07d309baf","analyzedAt":"2026-08-12T17:03:16.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}