From 4bdc7862bedd99caf19cf7db0fa3bd5d5a7a04ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Wed, 3 Jun 2026 20:14:24 +0200 Subject: [PATCH] browser: warn against top-level await in prompt Updates the synthesis prompt to explicitly state that the output is executed as a classic script, making top-level `await` a syntax error. --- src/browser/tools.zig | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/browser/tools.zig b/src/browser/tools.zig index 7e52640d..cfa0d1a0 100644 --- a/src/browser/tools.zig +++ b/src/browser/tools.zig @@ -127,11 +127,15 @@ pub const save_synthesis_prompt = \\JavaScript wherever they fit; fall back to evaluate(...) only for logic the \\builtins can't express. End with an extract(...) for any data the user \\wanted out. + \\The output MUST be valid JavaScript that runs as-is — it is executed as a + \\classic script (not a module), so top-level `await` is a syntax error; + \\`await` is only legal inside an `async` function. \\The builtins are synchronous and blocking: each returns its result - \\directly. Do NOT use async/await, .then, or Promises around them — write a - \\plain top-level script (e.g. `const data = extract(...)`, not - \\`await extract(...)`). evaluate(...) may run async JS inside the page, but - \\the evaluate(...) call itself still returns synchronously. + \\directly, so you never need `await` at all. Do NOT use async/await, .then, + \\or Promises around them — write a plain top-level script + \\(e.g. `const data = extract(...)`, not `await extract(...)`). evaluate(...) + \\may run async JS inside the page, but the evaluate(...) call itself still + \\returns synchronously. \\Output ONLY JavaScript source — no markdown fences, no commentary, no prose \\before or after. ;