Convert browser automations to direct API calls for speed and reliability.Browser automation is reliable, but it’s not always the fastest approach. When a site’s internal API is accessible from within the browser context, calling those endpoints directly is faster and less fragile than driving the UI. No selectors to maintain, no page rendering to wait for, and no DOM changes to break your script. Libretto captures all network traffic during a browser session, so your agent can inspect exactly which API calls the site makes and convert a UI-based workflow to direct requests.
Steps
Prompt your agent
Point the agent at the existing workflow file and ask it to convert to network requests.Include “Use the Libretto skill” so your agent uses Libretto’s network capture tools instead of guessing at API endpoints.
Example prompt
Watch the agent analyze the traffic
The agent runs the existing script to capture all network requests and responses, then examines the log to find API endpoints that return the data you need.If the site requires login, the agent opens a headed browser and you’ll log in as usual. Otherwise you don’t need to do anything during this phase.
Review the agent's approach
The agent reports what API endpoints it found and whether the site has bot protection. It recommends one of two approaches:
- In-browser fetch: call endpoints directly from within the browser’s JavaScript context. The requests share the browser’s cookies and TLS fingerprint, so they look identical to the site’s own requests. Faster, but only safe when the site doesn’t monitor for anomalous call patterns.
- Passive interception: set up a
page.on('response', ...)listener and let the site’s own code make the requests. Zero detection risk because no extra requests are made, but you’re limited to whatever requests the site naturally triggers. Safer, but less flexible. Use this when the site has bot protection.
Use passive interception, I don’t want to risk triggering their bot detection.
Review the rewritten workflow
The agent rewrites the workflow to use network requests instead of DOM extraction. Things to check:
- Endpoints: are the URLs and HTTP methods correct?
- Auth/cookies: does the new version handle authentication the same way as the original?
- Output shape: the return type should be identical to the browser-based version
- Error handling: API calls should check response status codes and handle failures gracefully
- Pagination: if the original script paginated through UI, the new version should paginate through the API
The original script also grabbed the comment count, but the new version doesn’t fetch that field from the API.
Check the validation run
The agent runs the rewritten workflow headless and shows you the output. Compare it to what the browser-based version returned. The data should match.If the output is wrong or incomplete, tell the agent what’s off:
The scores are all null. It looks like the API response has a different field name for that.
When to convert to network requests
- The site exposes a usable JSON API behind the UI
- You need to paginate deeply (fetching page 50 without clicking “next” 49 times)
- You want data the UI doesn’t display (hidden fields, metadata, IDs)
- Speed and reliability matter more than DOM fidelity
Related guides
One-shot workflow generation
Start from scratch. Give your agent a goal and let it build the workflow.
Debugging workflows
Reproduce failures and fix broken automations interactively.