Skip to content

API Reference

All classes live under the Pam\Browser namespace. This page documents version 1.0.1.

Pam\Browser\Browser owns one Chrome process and its CDP connection.

Method Returns Description
Browser::launch(?LaunchOptions $options = null, ?StreamConnector $connector = null) Browser Starts Chrome and connects to it. See Launching Chrome.
version() array Result of Browser.getVersion (product, protocolVersion, userAgent, …).
newPage(string $url = 'about:blank', float $timeoutSeconds = 30.0) Page Creates and attaches a tab; navigates when a URL is given.
createTarget(string $url = 'about:blank') string Creates a target and returns its id without attaching.
profileDirectory() string The profile directory in use.
close() void Closes the browser, connection, process, and temporary profile. Idempotent and never throws.

Pam\Browser\Page is one attached tab. Public read-only properties: targetId, sessionId.

Method Returns Description
enable() void Enables the Page and Runtime domains. Called by Browser::newPage().
navigate(string $url, float $timeoutSeconds = 30.0) void Navigates and waits for Page.loadEventFired.
evaluate(string $expression, bool $awaitPromise = true) mixed Runs JavaScript and returns the value by value.
waitForFunction(string $expression, float $timeoutSeconds = 30.0, float $pollIntervalSeconds = 0.05) mixed Polls until the expression is neither false nor null.
addScriptOnNewDocument(string $source) string Registers a script for every new document; returns its identifier.
exposeBinding(string $name, callable $callback) void Installs a global JS function that delivers decoded JSON to PHP.
pump(float $timeoutSeconds = 0.0) bool Processes one incoming CDP message; false on timeout.
captureScreenshot() string PNG bytes of the viewport.
setUserAgent(string $userAgent) void Overrides the user agent.
setBypassCsp(bool $enabled) void Toggles Content-Security-Policy bypass.
authenticate(string $username, string $password) void Answers proxy authentication challenges.
serveDocument(string $url, string $html) void Fulfills the document request for one exact URL with your HTML.
captureDocument(string $url, callable $callback) void Calls $callback(string $body) for responses with that exact URL.

Pam\Browser\Chromium\LaunchOptions is a readonly value object.

Property Type Default
executable ?string null (auto-detect)
userDataDirectory ?string null (temporary profile)
headless bool true
timeoutSeconds float 15.0 (greater than 0, at most 300)
arguments list<string> []
Class Purpose
Chromium\BrowserProcess launch(?LaunchOptions), close(), and the webSocketUrl and userDataDirectory properties.
Chromium\ExecutableLocator discover(?string $preferred = null) resolves the Chrome executable.
Connection command(), on(), waitForEvent(), pump(), close(). See Raw CDP Access.
Transport\Transport Interface: send(string), receive(float): ?string, close().
Transport\WebSocketTransport connect(string $url, ?StreamConnector $connector = null, float $timeoutSeconds = 10.0, int $maxPayloadBytes = 16_777_216).
Transport\StreamConnector Interface for opening the TCP stream; PamStreamConnector is the default.
Protocol\Event Readonly method, parameters, sessionId.
Variable Description
PAM_CHROME_PATH Chrome or Chromium executable to use when LaunchOptions::$executable is null.
Exception Thrown when
Exception\BrowserException Base class. Also thrown when Chrome cannot be found, started, or exposes no endpoint in time.
Exception\ProtocolException Extends BrowserException. Invalid or failed CDP traffic, navigation errors, JavaScript exceptions, timeouts.
Exception\CommandFailed Extends ProtocolException. Chrome rejected a command; has commandId, protocolCode, protocolMessage.