Shaf Lab

Browser automation

Driving a real browser from code to click, type, and inspect a page, with tools such as Playwright.

Browser automation means driving a real browser from code: opening a page, clicking, typing, and reading what appeared. Playwright is a common toolkit for this. You use it to test a UI, to scrape a flow that has no API, or to let an agent inspect and operate a web app the way a person would.

The reliable pattern is to wait for conditions, not for a fixed sleep. Locate elements in ways that survive a restyle, and keep tests or agent runs isolated so cookies and local data do not leak between jobs. Headless runs are fine for most CI; a headed browser is still useful when you are writing the first script and need to see what the page is doing.

For agents, treat the browser as a tool with a narrow interface: go to a URL, snapshot the page, click this target, type this text. Dumping the entire DOM into a prompt is slow and noisy. A compact accessibility tree or a targeted screenshot usually gives the model what it needs.

If you can call an API instead, do that. Automation is for the cases where the browser is the only interface, or where you are testing the interface itself.