diff --git a/internal/browserext/ext/background.js b/internal/browserext/ext/background.js index a37923ad4..f45b5ef35 100644 --- a/internal/browserext/ext/background.js +++ b/internal/browserext/ext/background.js @@ -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); diff --git a/internal/browserext/ext/manifest.json b/internal/browserext/ext/manifest.json index c9222a5e3..9f2741f14 100644 --- a/internal/browserext/ext/manifest.json +++ b/internal/browserext/ext/manifest.json @@ -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", diff --git a/internal/gateway/browser_e2e_test.go b/internal/gateway/browser_e2e_test.go index c09892c70..9e3447298 100644 --- a/internal/gateway/browser_e2e_test.go +++ b/internal/gateway/browser_e2e_test.go @@ -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)