Skip to content

Courses / Agentic AI / Module 13

Module 13: Browser and computer-use agents

10 h · theory 3 · hands-on 4 · project 2 · revision 1

You will be able to

  • Drive a browser with Playwright from an agent
  • Use a browser agent framework safely
  • Sandbox and approve every submit

Capstone increment: Optional: a browser tool that reads a status page, sandboxed and approval-gated.

Job-description skills: Browser automation · Lab tools: playwright, browser-use

1. When there is no API

Some systems only have a web interface: a vendor’s status page, an old admin console, a government portal. Browser agents read and act on pages the way a person does, and computer-use agents do the same on a whole desktop from screenshots. They are powerful and the least reliable tool in this course, so use them only where nothing better exists.

The loop is the agent loop with a browser as the tool: observe the page, decide an action, execute it with Playwright in an isolated profile, observe again. Guards decide which actions run and which wait for a person.

Goalread status pageObservea11y tree / screenshotDecideclick, type, scrollPlaywrightisolated profileResultextracted dataAllow-listdomains onlyApprovalsubmit, pay, sendNo secretsin the page or promptObserve, act, repeatGuardsnew page stateirreversible
Prefer an API when one exists. A browser agent is slow, brittle and exposed to every page it reads.

2. Seeing the page

There are two ways for a model to see a page. The accessibility tree (roles, names and states of elements) is compact text with stable references; Microsoft’s Playwright MCP server gives agents accessibility snapshots this way. Screenshots let a vision model see layout, canvas charts and anything the tree misses, at a higher token cost and with coordinate-based clicks.

Most robust agents combine them: the tree for finding and acting on elements, a screenshot when the tree isn’t enough. Prefer selectors by role and visible text over brittle CSS paths.

3. Frameworks and computer-use APIs

browser-use wraps Playwright in an agent loop with page state extraction; Playwright MCP exposes browser actions as MCP tools any host can use. Anthropic’s computer use and OpenAI’s computer-using agent let models drive a full virtual desktop from screenshots, with reference implementations that run in a container.

For known flows, write a deterministic Playwright script and let the agent call it as one tool. Use the open-ended browser agent only for exploration and unpredictable pages.

Common misconception: “A browser agent can replace our integration.” For a flow you run every day, a script is faster, cheaper and testable. Agents are for the long tail.

4. Safety

Every page the agent reads is untrusted input, and hidden text on a page is a classic injection. Run the browser in an isolated container and a fresh profile with no saved logins, restrict navigation to an allow-list of domains, block downloads by default, and hold every submit, purchase, send and sign-in for human approval.

Never put credentials or payment details in the page or the prompt. If a flow needs login, have a person sign in, or give the tool a dedicated, minimal account whose credentials the tool holds and the model never sees.

In production: Record a Playwright trace for every browser run. When an agent clicks the wrong thing, the trace viewer shows each page state and action.

5. Make it reliable enough

Expect failures from pop-ups, slow loads, layout changes and A/B tests. Wait for elements rather than sleeping, retry idempotent reads, take a screenshot on failure, and cap steps and time per task. Evaluate on a fixed set of recorded pages or a staging site so changes are measured, not guessed.

For the capstone, a browser tool that reads a vendor status page, sandboxed and approval-gated, is enough to show you can do this safely.

Hands-on: coding window

The coding window and the full VS Code lab are available after you sign in.

Sign in to code

Labs

Lab 13.1: Deterministic first

Write a Playwright script that reads a public status page and returns component states as JSON, with role-based selectors and a recorded trace.

Expected: A tool that returns structured status in under 5 seconds, and its trace file.

Lab 13.2: A contained browser agent

Run browser-use (or a Playwright MCP host) in Docker with a fresh profile, a domain allow-list and no downloads; give it a task on an unfamiliar status page.

Expected: A run log showing allowed and blocked actions, including one blocked navigation.

Lab 13.3: Browser tool (optional capstone increment)

Add a read_status_page tool to the capstone that uses the script for known vendors and the agent for others, with every submit held for approval.

Expected: Incident runs cite the vendor’s status; no submit happens without approval.

Go deeper

Videos

Further reading

GitHub repositories

Checkpoint quiz

1. When is a browser agent the right choice?
2. What does the accessibility tree give a model?
3. A page contains hidden text telling the agent to visit another site. Defence?
4. Which actions should always wait for a person?
5. How should a browser tool handle login?

Interview questions

  1. When would you use a browser agent instead of an API integration?
  2. Compare accessibility-tree and screenshot approaches for browser agents.
  3. How do you secure an agent that browses the open web?
  4. How do you make a browser agent reliable enough for production?
  5. Design a tool that reads vendor status pages for an ops assistant.

Ask the professor

Sign in to ask questions about this module.

Discussion

Community discussion appears here once giscus is configured (see README).