Remote browser


By default each run launches a local Chrome. To drive a remote one instead (Cloudflare Browser Run, a Chrome container behind a proxy…), give the library the address of its DevTools endpoint.

#Configuration

Variable Effect
PRESTAFLOW_BROWSER_WS ws:// or wss:// address of the remote browser's DevTools endpoint. When set, the suites connect to it and never launch a local Chrome, not even as a fallback: if the connection fails, the run fails.
PRESTAFLOW_BROWSER_WS_TOKEN Optional. Sent as Authorization: Bearer <token> in the WebSocket handshake. It never appears in error messages, logs, the .browser file or the results.
Copied!
1PRESTAFLOW_BROWSER_WS="wss://api.cloudflare.com/client/v4/accounts/<account>/browser-run/devtools/browser?keep_alive=60000" \
2PRESTAFLOW_BROWSER_WS_TOKEN="<api token>" \
3vendor/bin/prestaflow run tests

Unset or empty PRESTAFLOW_BROWSER_WS: nothing changes, a local Chrome is launched as before.

#What changes with a remote browser

  • Window size and user agent. A remote browser ignores launch options, so PRESTAFLOW_WINDOW_SIZE_WIDTH / _HEIGHT, PRESTAFLOW_USER_AGENT and the device presets of visual suites are applied to every page instead, as its viewport size.
  • One session per process, kept in memory only. Changing the device (resetBrowser()) closes the session; the next page opens a new one.
  • Timeouts. PRESTAFLOW_CDP_TIMEOUT, the timeout in milliseconds of the synchronous calls to Chrome (5000 by default), applies as with a local Chrome.

#From your own code

Code that connects by itself can use the same entry point:

Copied!
1use PrestaFlow\Library\Support\RemoteBrowser;
2 
3$browser = RemoteBrowser::connect($uri, $headers, $timeoutMs, $windowSize, $userAgent);

It accepts only ws:// and wss:// addresses, and reads wss:// without blocking: with the default socket of the WebSocket client, one Chrome call in two or three waited for the 5-second socket timeout over TLS.