dnd-kit and SortableJS may require several intermediate mousemove events before they recognize a drag. A tool that jumps directly from pressing to releasing can report success even though the page never recognized the gesture and the card did not move.
The answer is not to run the entire task through slower, screenshot-based computer use. Start with Playwright for navigation, reading, clicking, and form filling. Switch to computer use only for the interaction that needs realistic pointer movement, then continue without losing the browser’s open tabs, page state, or the agent’s conversation context.
This cookbook demonstrates three ways to make that handoff between Playwright and computer use with @onkernel/browser-loop, KERNEL’s tool package for browser agents.
The example task
Every snippet below runs the same task against magnitasks.com, a public Kanban-style board:magnitasks.com’s board uses pointer-based drag-and-drop, so it’s a small, honest example of the failure mode this cookbook exists for.
Playwright vs. computer use
An agent tool is a callable operation that lets the model read browser state or take an action. The model selects a tool and supplies its inputs; the harness executes the operation and returns the result to the model. A toolset is the collection of tools available during a run.browser-loop provides two toolsets for controlling the same browser session. Playwright tools (loop.toolsets.browser()) find page elements through the DOM and act on them by reference. Computer-use tools (loop.toolsets.computer()) read screenshots and control the pointer using screen coordinates.
Make Playwright your default toolset: it’s faster and cheaper per action. Reach for computer use for the specific interactions that don’t hold up to DOM-ref execution: drag-and-drop on a pointer-sensor library, canvas-drawn UI, a file picker’s native dialog, anything a screenshot can see that the accessibility tree can’t reliably resolve.
Picking a harness
The snippets below usebrowser-loop with @earendil-works/pi-agent-core’s AgentHarness.
compiled.apply(harness) swaps a running harness onto a new (model, tools) pair without resetting browser refs, open tabs, or the conversation transcript, which is what makes the mid-session handoff between Playwright and computer-use tools a single method call. The model that picks up with computer-use tools still has the entire Playwright conversation as context, and knows what it already tried.
If you use a different agent harness, the same concepts apply. If your setup doesn’t expose an equivalent live tool-catalog swap, implement the handoff as two sequential calls instead: run Playwright to completion or failure, then start a fresh call with computer-use tools and carry forward what happened as plain-text context in the new prompt. The Per-Tool Limit example below shows what to include in that handoff message.
Setup
KERNEL_API_KEY and a provider key for whichever model LOOP_MODEL points at (anthropic:claude-sonnet-5 by default, so ANTHROPIC_API_KEY):
Three ways to hand off between Playwright and computer use
All three run Playwright first and switch to computer use once it stops making progress. They differ in what you need to know about the task at integration time:
If you can name the risky tool, use Per-Tool Limit — it’s the only one of the three that’s both precise and free of tuning. The other two exist for when the task genuinely isn’t known until runtime.
Per-Tool Limit
Use this when you’re integrating against a known, fixed target and you already know — or can find in one test run — which specific Playwright tool needs help from computer-use tools.PLAYWRIGHT_TOOLS_WITH_ATTEMPT_LIMITS names those tools; the harness counts completed attempts for each one and hands off when any tool reaches PER_TOOL_ATTEMPT_LIMIT. Most DOM-ref tools report success even when they don’t produce the intended effect, so an attempt against a still-unfinished task is itself the signal. ACTION_SAFETY_CAP is a backstop for a run that never reaches a per-tool limit.
Total Tool-Call Limit
Use this when you know the general category of task but not the specific action likely to need computer use, so naming one tool up front isn’t realistic.TOTAL_TOOL_CALL_LIMIT counts every completed Playwright tool call and hands off when the total reaches that limit, regardless of which tools the agent used.
Set the limit high enough to cover the task’s legitimate setup — navigation, filtering, form-filling — before it reaches the action that needs computer use. There’s no principled way to pick the number without running the task and looking; that’s the direct cost of not needing to know which tool will fail.
Model-Directed Handoff
Use this when the task isn’t known at integration time at all — a general-purpose agent product where an end user’s request determines the site, the workflow, and whether anything needs computer use.loop.toolsets.mixed() gives the model both Playwright and computer-use tools from the start; a system prompt steers it toward the cheaper browser_* tools by default and toward computer_* tools once a browser_* action doesn’t produce the expected effect. There’s no handoff code to write.
The tradeoff is that a system prompt is a soft constraint on both axes that matter: how long the model sticks with Playwright tools before trying computer use, and which computer-use tool it reaches for once it does. Nothing here enforces a hard bound, and nothing guarantees it picks the purpose-built tool for the job over reassembling the effect from lower-level primitives.
Choosing between them
As a starting rule, reach for Per-Tool Limit first, even if it costs you one exploratory run to find the tool name. Use Total Tool-Call Limit only when the task varies enough that naming a specific tool isn’t realistic. Use Model-Directed Handoff only when you can’t write task-specific logic at all — and if you do, consider pairing it with a hard action cap as a backstop against its unbounded soft constraint.
Notes
- None of the three hand control back. Once a run switches to computer-use tools, Playwright doesn’t get another turn in that session. Fine for a single bounded task; worth revisiting for a longer-running agent that could benefit from returning to the cheaper tools once computer-use tools re-establishes progress.
- Swap models freely. All three default to
anthropic:claude-sonnet-5viaLOOP_MODEL. UselistLoopModels()from@onkernel/browser-loop/pito see everything else the catalog supports for both toolsets. - The whole handoff is recorded on one video. Each script wraps the run in
client.browsers.replays.start()/.stop(), so the Playwright attempt and the computer-use recovery land on the same replay. The replay URL prints as soon as recording starts and again once it’s stopped and finished processing.
Next steps
- Computer Controls — the OS-level API that computer-use tools drive
- Computer Use overview — running computer-use models on KERNEL more generally
- Replays — record a session end to end
- Stealth mode — reduce how often a page notices the automation in the first place