From 8ccff6c98b04666401b041002ca4aab997e1ff22 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 19:57:27 +0530 Subject: fix(domains): report a page-side throw instead of blaming the ref MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit runOnElement checked only whether Runtime.callFunctionOn reached Chrome, not whether the function it ran threw. A page-side exception left result.value undefined, the result guard rejected it, and browser_fill, browser_focus and browser_select_option all reported "No element matched: " for an element that was there — sending the agent to re-snapshot a ref that was fine and discarding the real error. The throw is now surfaced as cdp_error carrying the exception text, which is distinguishable from both the no-match and stale-ref paths; those still fire for a genuinely missing or stale element. The selector path already reported throws correctly via evaluateJs. Report: docs/superpowers/reports/2026-07-26-bug-audit.md#f2 Co-Authored-By: Claude Opus 5 (1M context) --- src/domains/form.ts | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/domains/form.ts b/src/domains/form.ts index d8cbf87..78e3db1 100644 --- a/src/domains/form.ts +++ b/src/domains/form.ts @@ -48,6 +48,13 @@ const runOnElement = async ( returnByValue: true, }); if (!r.success) return r; + if (r.data.exceptionDetails !== undefined) { + return err({ + kind: "cdp_error", + message: `page function threw: ${r.data.exceptionDetails.text}`, + details: { ref: opts.ref }, + }); + } return ok(r.data.result.value); } if (opts.selector === undefined) { -- cgit v1.2.3