WebSocketRoute

Playwright\WebSocket\WebSocketRouteInterface

Methods

close()

void

Closes one side of the WebSocket connection.

function close(array|CloseOptions $options = []): void

connectToServer()

WebSocketRouteInterface

Connects to the actual WebSocket server. Returns the server-side WebSocketRoute instance.

function connectToServer(): WebSocketRouteInterface

onClose()

void

Handles WebSocket closure. When set, disables default closure forwarding.

function onClose(callable $handler): void

onMessage()

void

Handles messages sent by WebSocket (from page or server). Stops automatic message forwarding.

function onMessage(callable $handler): void

send()

void

Sends a message to the WebSocket. Can send to page or server depending on context.

function send(string $message): void

protocols()

array

Subprotocols the page asked for in the WebSocket constructor; empty when it asked for none.

function protocols(): array

url()

string

Returns the URL of the WebSocket created in the page.

function url(): string