diff options
| author | Aman Kumar <145339995+amankumarsingh77@users.noreply.github.com> | 2026-07-05 13:15:22 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-05 13:15:22 +0530 |
| commit | 26daf87896d6645fe9be71460d2868755a4f939f (patch) | |
| tree | f81876c314ee78c742e9351ceea6b53a6852ab7b /src/client.ts | |
| parent | cf770d148082c58cf13102c9ea57030e0e404ef4 (diff) | |
fix: make dispatch_key fire legacy keyCode handlers and tighten execute_js IIFE wrap (#9)
- browser_dispatch_key now sets keyCode/which on the synthesized KeyboardEvent
(both ref and selector paths) so handlers checking e.keyCode === 13 fire.
- browser_execute_js IIFE auto-wrap triggers only when the source starts with a
return statement, not on any substring "return " (which silently produced
undefined for bare expressions).
- browser_fill guidelines point at dispatch_key for tag-input submission and the
snapshot+click recipe for custom dropdowns.
Bump to 0.8.1.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'src/client.ts')
| -rw-r--r-- | src/client.ts | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/client.ts b/src/client.ts index 3c79f1a..724a711 100644 --- a/src/client.ts +++ b/src/client.ts @@ -170,12 +170,14 @@ export const createBrowserClient = (opts: BrowserClientOptions): BrowserClient = const evaluateJs = async (expression: string, sessionId?: string): Promise<Result<unknown, CdpError>> => { // Heuristic IIFE wrap: legacy convenience that lets agents write - // `return foo` instead of `(() => foo)()`. False-positive on substring - // `"return "` inside string literals or comments — agents that hit this - // can pass an explicit IIFE instead. - const wrapped = expression.includes("return ") && !expression.trim().startsWith("(") - ? `(function(){${expression}})()` - : expression; + // `return foo` instead of `(() => foo)()`. Only wrap when the trimmed + // source *starts with* a return statement — a bare expression, or one that + // merely mentions `return` inside a string literal or comment, is passed + // through untouched (previously any substring `"return "` triggered a wrap, + // silently turning such expressions into `undefined`). + const trimmed = expression.trim(); + const isReturnStatement = /^return[\s(]/.test(trimmed); + const wrapped = isReturnStatement ? `(function(){${expression}})()` : expression; const r = sessionId ? await session.callOnTarget("Runtime.evaluate", { expression: wrapped, returnByValue: true, awaitPromise: true }, sessionId) : await session.call("Runtime.evaluate", { expression: wrapped, returnByValue: true, awaitPromise: true }); |
