WebSocket

Playwright\WebSocket\WebSocketInterface

Represents a page WebSocket. The socket exposes its URL and browser-emitted lifecycle or frame events. Send frames or wait for socket activity through the active page connection.

Methods

isClosed()

bool

Indicates that the web socket has been closed.

function isClosed(): bool

url()

string

Contains the URL of the WebSocket.

function url(): string

on()

void

Adds an event listener for a WebSocket event. Supported events: 'close', 'framereceived', 'framesent', 'socketerror'.

function on(string $event, callable $listener): void

once()

void

Adds a one-time event listener for a WebSocket event.

function once(string $event, callable $listener): void

removeListener()

void

Removes an event listener for a WebSocket event.

function removeListener(string $event, callable $listener): void

waitForEvent()

array

Waits for event to fire and passes its value into the predicate function.

function waitForEvent(string $event, array|WaitForEventOptions $options = []): array