switon / browser
Headed agent tab for Switon: snapshot refs, then click and type on that page
v1.0.0
2026-08-22 14:25 UTC
Requires
- php: >=8.3
- ext-json: *
- switon/ai: ^1.0
- switon/cdp: ^1.0
- switon/core: ^1.0
- switon/tooling: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/testing: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Headed agent tabs for Switon: a page the agent names, an accessibility snapshot with eN refs, then click and type on that page.
Highlights
- Tabs the agent names: every browser tool takes a
tabid the agent chooses. The same id reuses that page and itseNrefs; a new id opens another tab. Agents do not share tabs. Chrome is still one process.browser_closecloses one id; the rest close when the agent is collected. - Snapshot refs: read the page as text. Interactive rows are
eNids, addressing the node directly so shadow DOM and iframes are reachable. Text on screen is included. Text below the fold is counted in the header and left out; a control there stays as one(offscreen)line. Prose past a fixed character budget folds into one count line, so a long article costs about what its opening screen does. - Act on the page: click and type those refs. A screenshot saves the current PNG.
- Explain what broke:
browser_consolereturns console output, uncaught exceptions, and failed requests;browser_inspectreturns computed styles and the box of an element. - Know that it worked:
browser_assertchecks a ref — or a CSS selector, for text the page shows back without a ref — against a condition, and retries, so a page that updates late still passes.
Silent page reads and cookie-bearing HTTP live on switon/cdp.
Tools
| Tool | Role |
|---|---|
browser_navigate |
open a URL on a named tab and return the snapshot |
browser_close |
close one named tab, return the id that was closed |
browser_snapshot |
re-read the page as text with eN refs |
browser_click |
click a ref, return the new snapshot |
browser_type |
replace a ref's text, optionally submit |
browser_take_screenshot |
save a PNG of the tab |
browser_console |
console lines, exceptions, and 4xx/5xx responses |
browser_inspect |
computed CSS and the box for a ref |
browser_scroll |
reach elements marked (offscreen), or scroll to look lower |
browser_assert |
check that a ref is visible, says text, has a value, is enabled or checked |
browser_console is the one to reach for when a page did not behave as expected: an uncaught exception and a failed request never appear in a snapshot.
Installation
composer require switon/browser
Quick Start
use Switon\Browser\HeadedBrowserInterface; use Switon\Core\Attribute\Autowired; class AgentTab { #[Autowired] protected HeadedBrowserInterface $browser; public function open(string $url): string { $this->browser->navigate($url); return $this->browser->snapshot(); } }
Docs: https://github.com/switon-php/browser/blob/main/docs/README.md
License
MIT.