From 28578d1d6237cdec3f613a3ed9fa6e888dd71a6b Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Thu, 30 Apr 2026 17:52:26 +0530 Subject: Replace dynamic tool registration with browser_run_script Remove register_tool/remove_tool/list_dynamic_tools and the entire dynamic-tools.ts module. Replace with a single browser_run_script tool that executes temporary scripts from disk with daemon access. Scripts are now written to disk before execution, making them auditable and re-runnable. Same bindings (daemon, require, params, etc.) as before via the same AsyncFunction mechanism. --- src/prompt.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/prompt.ts') diff --git a/src/prompt.ts b/src/prompt.ts index 26c41b5..8e3b727 100644 --- a/src/prompt.ts +++ b/src/prompt.ts @@ -39,6 +39,29 @@ to interact with pages visually, and other tools alongside them. | browser_wait | Wait N seconds | | browser_wait_for_load | Wait for document.readyState === 'complete' | | browser_handle_dialog | Accept or dismiss a JS dialog | +| browser_run_script | Execute a temporary script file with daemon access (write script to disk, then run) | + +### Temporary Scripts + +When the built-in tools aren't enough for a multi-step workflow, write a temporary +script to disk and execute it with browser_run_script. The script runs in the +harness process with direct access to the browser daemon and Node.js APIs. + +\`\`\` +write("/tmp/scrape-pages.js", \` + const results = []; + for (const url of params.urls) { + await daemon.cdp("Page.navigate", { url }); + await new Promise(r => setTimeout(r, 2000)); + const data = await daemon.evaluateJS("document.title"); + results.push({ url, title: data }); + } + return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] }; +\`) +browser_run_script("/tmp/scrape-pages.js", { urls: [...] }) +\`\`\` + +Script bindings: params, daemon, require, signal, onUpdate, ctx, console, fetch, JSON, Buffer, setTimeout, clearTimeout. ### Common Patterns @@ -74,5 +97,10 @@ browser_switch_tab(targetId: "...") → switch to a tab browser_screenshot() → visually inspect the page browser_execute_js("document.querySelector('.main').innerText") → extract content \`\`\` + +**Temporary Scripts (extending the harness):** +\`\`\` +write("/tmp/extract.js", "...script with daemon access...") → browser_run_script("/tmp/extract.js") +\`\`\` `; } -- cgit v1.2.3