mode=auto) and response_type=markdown, Browser with Playwright
How it works
- The agent describes the task. A read-only task is a URL. An interactive task is a URL plus a list of steps (
fill,click,wait_for_text,goto). - The router picks the primitive. No steps: the task goes to Fetch with
mode=auto, which renders JavaScript and switches to premium proxies only when the page needs them. Steps: the task goes to Browser. - Fetch returns markdown. One request, one page, ready for the model’s context.
- Browser runs the steps. Playwright connects to
wss://browser.zenrows.comover CDP, runs each step in order, returns the page text, and closes the session.
Ask your AI agent
With the Zenrows MCP server connected to Claude, Cursor or any MCP client, your agent already has both paths: fast reading and a full browser. Paste this prompt:Build the router
Install the dependencies:pip install requests playwright for Python, or npm install playwright-core for Node.js. Browser runs in the cloud, so there is no local browser to download.
finally block closes the browser on every path, so no session stays open after the task. The login page uses the demo credentials shown on scrapingcourse.com/login.
Expose it as agent tools
Give the model the two functions as tools. The definitions use JSON Schema, which every agent framework accepts: passinput_schema as-is to the Anthropic API, or rename it to parameters for OpenAI function calling and most other frameworks.
Python
read_page for reading and browser_task only when a step needs interaction. For a complete agent loop around these tools, see Build a research agent with live web data.
Example output
Output of the router, one Fetch task and one Browser task:Customize it
Troubleshooting
- A click step times out waiting for navigation: the click submits a form. Keep
no_wait_after=True(noWaitAfter: truein Node.js) on clicks and follow them with await_for_textstep for text on the next page. wait_for_texttimes out: the text never appeared, often because the previous step failed (wrong credentials, wrong selector). Returnpage.evaluate("document.body.innerText")in the error to see what the page shows.- The model uses the browser for simple reads: tighten the
browser_taskdescription, for example “Only call this when a step needs a click, a form or a login.” - Fetch returns
422: the page wasn’t retrieved. Keepmode=autoand set the client timeout to 180 seconds so it has time to escalate, see error codes.
Related recipes
Build a research agent with live web data
Wire Zenrows tools into an LLM agent loop.
Log in once and reuse the session
Save the logged-in state and reuse it across sessions.
Connect Playwright or Puppeteer to Zenrows Browser
Every connection option for Browser.
Connect your AI agent to Zenrows
Give Claude, Cursor or your own agent live web access.