switon / cdp
Headless Chrome for Switon: open a page, wait, read HTML, and send cookie-bearing HTTP
v1.0.0
2026-08-22 14:25 UTC
Requires
- php: >=8.3
- ext-json: *
- switon/core: ^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
Headless Chrome for Switon: open a page, wait for an element, read the rendered HTML, and send cookie-bearing HTTP from that profile.
Highlights
- Background page: open a URL with no visible window, wait until an element appears, and read the rendered HTML.
- Site cookies: send
GETandPOSTwith the cookies already stored for that profile. An API on the site starts from that site's document. - Visible debugging: click an element, fill a field, and capture the current screen.
- Front-end diagnostics: read console output, uncaught exceptions, and failed requests; inspect computed styles; run JavaScript in the tab.
- Separate profiles: headless uses
~/.switon/chrome/headlesson port 59222. A visible window uses~/.switon/chrome/headedon port 59223. A login stays in the profile that stored it.
Installation
composer require switon/cdp
Quick Start
use Switon\Cdp\HeadlessChromeInterface; use Switon\Core\Attribute\Autowired; class PageReader { #[Autowired] protected HeadlessChromeInterface $chrome; public function html(string $url): string { $page = $this->chrome->open($url); try { $page->wait('main'); return $page->content(); } finally { $page->close(); } } }
Docs: https://github.com/switon-php/cdp/blob/main/docs/README.md
License
MIT.