browser_add_init_script
Add a JavaScript init script that runs before any page script on every navigation. Use it to preempt anti-bot checks like Cloudflare or Turnstile by calling it before navigating to the target URL.
Instructions
Register JavaScript that runs before any page script, on every navigation (Playwright's page.addInitScript — always in the page's main world). Unlike browser_evaluate, this is proactive: it wins the race against a site's own inline (e.g. Cloudflare/Turnstile checks that run synchronously on document parse), which a reactive evaluate call issued over the MCP connection cannot. Call this BEFORE browser_navigate to the target URL — it has no effect on a page already loaded, only on the page it's called on and future navigations of that same page. Scoped to the current page only.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "browser_add_init_script"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| script | No | Deprecated alias for function. | |
| function | No | Function body/expression to install as the init script, e.g. '() => { window.foo = 1; }'. |