{"record":{"id":"53f5be9abaf988e2","repo":"stablyai/orca","slug":"browser-eval-error","errorCode":"browser_eval_error","errorMessage":"${exceptionDetails.exception?.description ?? exceptionDetails.text}","messagePattern":"\\$\\{exceptionDetails\\.exception\\?\\.description \\?\\? exceptionDetails\\.text\\}","errorType":"error_code","errorClass":"BrowserError","httpStatus":null,"severity":"error","filePath":"src/main/browser/agent-browser-bridge.ts","lineNumber":1575,"sourceCode":"  ): Promise<BrowserEvalResult> {\n    return this.enqueueTargetedCommand(\n      worktreeId,\n      browserPageId,\n      async (_sessionName, target) => {\n        const wc = this.requireTargetWebContents(target)\n        let releaseDebugger = (): void => {}\n        try {\n          releaseDebugger = acquireElectronDebugger(wc).release\n          const { result, exceptionDetails } = (await wc.debugger.sendCommand('Runtime.evaluate', {\n            expression,\n            returnByValue: true,\n            awaitPromise: true\n          })) as {\n            result: { value?: unknown; description?: string }\n            exceptionDetails?: { text: string; exception?: { description?: string } }\n          }\n          if (exceptionDetails) {\n            throw new BrowserError(\n              'browser_eval_error',\n              exceptionDetails.exception?.description ?? exceptionDetails.text\n            )\n          }\n\n          const currentTarget = this.resolveCommandTarget(worktreeId, target.browserPageId)\n          if (currentTarget.webContentsId !== target.webContentsId) {\n            throw new BrowserError(\n              'browser_tab_changed',\n              `Browser page ${target.browserPageId} changed while evaluating; retry the command`\n            )\n          }\n          return {\n            result:\n              result.value !== undefined\n                ? typeof result.value === 'object' && result.value !== null\n                  ? JSON.stringify(result.value)\n                  : String(result.value)","sourceCodeStart":1557,"sourceCodeEnd":1593,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/browser/agent-browser-bridge.ts#L1557-L1593","documentation":"Thrown by evaluate() after a CDP `Runtime.evaluate` call returns `exceptionDetails` — the JavaScript expression was delivered to the page and executed, but it threw a runtime exception inside the browser context. The message is the exception's description (preferred) or the generic exceptionDetails.text. This is distinct from a transport/protocol failure: the eval ran, the page's JS threw.","triggerScenarios":"Calling evaluate(expression) where `expression` is syntactically valid JS that throws at runtime — e.g. accessing a property of undefined, calling a non-function, a rejected awaited promise (awaitPromise: true surfaces rejection), or referencing a variable not in the page's scope. CDP populates exceptionDetails.exception.description with the JS stack.","commonSituations":"Agent-generated eval expressions that assume DOM elements exist when they don't (null deref); evaluating an expression that awaits a promise that rejects; CSP or page-context differences causing a function to be undefined; expressions referencing Node.js globals not present in the browser.","solutions":["Read the exception description in the message — it contains the JS stack and error type from the page.","Wrap the eval expression in try/catch inside the JS itself so it returns a descriptive string instead of throwing.","Add null/existence guards in the expression (e.g. `document.querySelector('#x')?.textContent ?? 'not found'`).","Verify the expression runs in the page's main world context and not an isolated world where page globals are absent."],"exampleFix":"// before\nawait bridge.evaluate('document.querySelector(\"#missing\").value')\n// after\nawait bridge.evaluate('(document.querySelector(\"#missing\")?.value) ?? null')","handlingStrategy":"try-catch","validationCode":"// validate expression syntax before sending to CDP\ntry { new Function(expression) } catch (e) { throw new Error(`Invalid eval expression: ${e.message}`) }","typeGuard":null,"tryCatchPattern":"try {\n  return await bridge.evaluate(expression, worktreeId, browserPageId)\n} catch (e) {\n  if (e instanceof BrowserError && e.code === 'browser_eval_error') {\n    // the expression threw inside the page — fix the expression, don't retry blindly\n    throw new Error(`Page eval failed: ${e.message}`)\n  }\n  throw e\n}","preventionTips":["Wrap eval expressions in optional chaining and nullish coalescing to avoid null derefs","Validate expression syntax client-side before sending to CDP","Return JSON-safe primitives from eval expressions to avoid serialization issues","Use try/catch inside the eval expression itself and return an error string"],"tags":["browser","javascript-eval","cdp","runtime-error"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}