Example prompt
We have a browser script at ./integration.ts that is supposed to go to Availity and perform an eligibility check for a patient. But I’m getting a broken selector error when I run it. Fix it. Use the Libretto skill.The agent reproduces the failure, snapshots the broken state, finds the correct selector in the current DOM, patches the code, and re-runs to confirm.
The debugging workflow
Run the failing script
--headed so you can watch the browser and see where it stops. Name the session something descriptive — you’ll use it for all subsequent commands.Browser stays open at the failure point
When a workflow fails, Libretto keeps the browser open and returns control to the CLI. The agent sees the error message and knows to inspect the current page state before touching any code.
Snapshot the broken state
Test selectors with exec
Once the snapshot identifies candidate selectors, the agent validates them against the live page:If the count is
0, the selector doesn’t match. Try alternatives until you find one that returns 1:Fix the code
With the correct selector confirmed, the agent updates the workflow file. Read the code generation rules before editing production code — Playwright locator APIs, no
querySelectorAll in page.evaluate(), type-safe output.Using pause() as a breakpoint
If you need to stop a workflow at a specific point — not at failure, but at a known state you want to inspect — add a pause() call:
pause() call with the browser open. Inspect, test selectors, then resume:
pause() is a no-op when NODE_ENV === "production", so you can leave it in during development and it won’t affect production runs. Remove it once you’re done debugging.
Reading logs for error context
The session log at.libretto/sessions/<session>/logs.jsonl contains structured entries for every step the workflow took. Use jq to find the error:
Common errors
Broken selectors The most common failure. A selector that worked last week no longer matches because the site updated its markup. Fix:- Use
snapshotto see the current DOM and identify the updated element - Use
execto test new selectors against the live page - Prefer stable selectors:
data-testidattributes, ARIA roles, and visible label text over class names and positional selectors
attemptWithRecovery() from the Library API to handle known popup patterns:
waitForSelector or locator action times out because the expected element never appeared. Check the snapshot to see what the page actually shows — it may be a loading spinner, an error state, or a redirect you didn’t expect. The structured log entry will include which selector was being waited for.
Tips
Related guides
One-shot script generation
Build a new automation from scratch without any prior knowledge of the site.
Interactive script building
Show the workflow manually and let your agent turn it into reusable code.