browser: browser_evaluate calls an async()=> function and awaits it
The check that tells a function from an expression wanted a space after
async, so `async()=>{…}` was evaluated as an expression: the function
itself came back, serialized as {}, and its body never ran. And a
parameter list could hold parentheses, so `(async()=>{…})()` counted as
a function and its promise was called ("is not a function"). async may
now touch its parameters, and a parameter list holds no parentheses.
The extension goes to 0.1.2.
Found driving X through magpie-browser from Claude Code.
Run on mote (Chrome for Testing 1234):
- MAGPIE_BROWSER_CHROME=… go test ./internal/gateway -run
'TestBrowser.*InARealBrowser' -count=1: ok (46.5s). Five new evaluate
cases: async()=>, async () =>, async function, an async IIFE and
Promise.resolve, each answering "awaited".
- Broken by hand: with origin/main's background.js the test is red at
the first case (async()=>… doesn't say "awaited").
- go test ./internal/browserext: ok. gofmt -l: clean.
Not run: the full suite; not tried in Edge or Firefox.
This commit is contained in:
@@ -669,7 +669,9 @@ const TOOLS = {
|
||||
const t = await ready(session, args);
|
||||
if (t.dialog) return fail(notices(t).join("\n"));
|
||||
const src = String(args.script).trim();
|
||||
const fn = /^(async\s+)?(function\b|\([^)]*\)\s*=>|[A-Za-z_$][\w$]*\s*=>)/.test(src);
|
||||
// async may touch its parameters (async()=>…), and a parameter list
|
||||
// holds no parentheses, so (async () => …)() stays an expression.
|
||||
const fn = /^(async\b\s*)?(function\b|\([^()]*\)\s*=>|[A-Za-z_$][\w$]*\s*=>)/.test(src);
|
||||
let r;
|
||||
if (args.ref) {
|
||||
const el = await find(t, args.ref);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "Magpie Browser",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"description": "Lets the agents you run through Magpie use this browser: your tabs, signed in to the sites you use.",
|
||||
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwjVk++2N/+l0PX53QSgXvBmDiyIOFXPDRTSo6l7HfM633QbDes2FXjS09l6hY33gsVX9eXE9O+94jQD2SVKSBn8V/EsL3f7mbNfkBqsZ4hYF3ogYxHUjJD6wjKHMFZQi54ArMZBI/psMUBbIjVTeuU9EGwnxoYU5umC8UHvEwkb4ZO0lprP3PGbHDjxrNi5fdFI8azVjyX0zlYlSw2wv0bCAZdkWuRoZWWgKdQwpdtRHrDQMnulWXT5DmNLYDpHgCreDrVaVLXzIAblSLOkZFo/T5xBiicmEbkWPbb8d3iE0OQStm1HYLdp4LLeKnnU6B7Kj/woOFt1uGIwoMqPzswIDAQAB",
|
||||
"minimum_chrome_version": "116",
|
||||
|
||||
@@ -103,6 +103,17 @@ func TestBrowserToolsInARealBrowser(t *testing.T) {
|
||||
|
||||
ok("browser_scroll", map[string]any{"direction": "down", "amount": 600}, "Scrolled down 600px")
|
||||
ok("browser_evaluate", map[string]any{"script": "window.scrollY"}, "600")
|
||||
// An async function is called and awaited however it is spaced, and
|
||||
// an expression that calls one is awaited, not called again.
|
||||
for _, script := range []string{
|
||||
"async()=>{await new Promise(r=>setTimeout(r,50));return 'awaited'}",
|
||||
"async () => { await null; return 'awaited' }",
|
||||
"async function(){ await null; return 'awaited' }",
|
||||
"(async()=>{await new Promise(r=>setTimeout(r,50));return 'awaited'})()",
|
||||
"Promise.resolve('awaited')",
|
||||
} {
|
||||
ok("browser_evaluate", map[string]any{"script": script}, `"awaited"`)
|
||||
}
|
||||
ok("browser_text", nil, "Magpie fixture", "Bottom of the page")
|
||||
|
||||
shot := call("browser_screenshot", nil)
|
||||
|
||||
Reference in New Issue
Block a user