fix: prefer exception.description over text for eval errors

SH
3d ago
+331-4

why

browse eval returns just "Uncaught" for every JavaScript error, losing the actual error message and stack trace.

Data (PostHog, 14 days to Nov 20 2026):

  • eval unexpected: 10,685 fails across 1,010 installs (1.42% of evals)
  • eval is the most-run command at 51k runs/day and 482 users/day (37% of CLI DAU)
  • Agents retry blindly: an eval failure is followed by another eval failure 3,998 times, versus 2,444 times by a success

Root cause: page.ts ~L1891 uses exceptionDetails.text ("Uncaught") before exception.description. Same pattern in frame.ts ~L186 and ~L198.

what changed

Extension (packages/extension/understudy/page.ts, frame.ts):

  • Use exceptionDetails.exception?.description || exceptionDetails.text || "Evaluation failed" in all three places

CLI (packages/cli/src/lib/driver/commands/page-info.ts):

  • On eval catch, rethrow RPC timeout/closed errors as-is
  • Otherwise rethrow DriverError(msg, { code: "eval_exception" }) so user-code errors are typed

Users see the improved error messages only after a Stagehand SDK release and CLI dependency bump. The CLI pins @browserbasehq/stagehand@4.4.0. The CLI error-typing change (eval_exception code) takes effect immediately.

Before (main/0.12.0):

$ browse eval 'throw new Error("boom")' --session test --local --headless
Uncaught

$ browse eval '1+' --session test --local --headless
Uncaught

After (CLI built against this branch's stagehand, local link not committed):

$ browse eval 'throw new Error("boom")' --session test-after --local --headless
Error: boom
    at <anonymous>:1:7

$ browse eval '1+' --session test-after --local --headless
SyntaxError: Unexpected end of input

test plan

  • CLI unit tests for eval error wrapping (tests/driver-commands.test.ts)
    • wraps eval exceptions in DriverError with eval_exception code
    • rethrows RPC closed errors from eval without wrapping
    • rethrows target-closed errors from eval without wrapping
  • Manual test on main confirming "Uncaught" output for both throw and syntax errors
  • Manual test with local SDK link confirming full error messages
  • pnpm run -C packages/cli test:cli (699 tests passed)
Open in Web Open in Cursor 

Summary by cubic

Fixes browse eval so user-code failures show the actual error message and stack trace instead of just "Uncaught".

  • The extension now prefers exceptionDetails.exception?.description over exceptionDetails.text in page.ts and both eval paths in frame.ts.
  • The CLI wraps user-code eval errors in a typed DriverError with code eval_exception, while rethrowing transport-level RPC errors (connection closed, target closed) as-is.
  • The CLI error typing takes effect immediately; the improved messages require a Stagehand SDK release and CLI dependency bump (browse pins @browserbasehq/stagehand@4.4.0).
  • Adds a single changeset covering browse, the extension, and the SDKs, plus unit tests for error wrapping and frame error message extraction.