WebSocket
The WebSocket class represents websocket connections in the page.
Methods
isClosed
Added before v1.9Indicates that the web socket has been closed.
Usage
WebSocket.isClosed();
Returns
url
Added before v1.9Contains the URL of the WebSocket.
Usage
WebSocket.url();
Returns
waitForFrameReceived
Added in: v1.10Performs action and waits for a frame to be sent. If predicate is provided, it passes WebSocketFrame value into the predicate
function and waits for predicate(webSocketFrame)
to return a truthy value. Will throw an error if the WebSocket or Page is closed before the frame is received.
Usage
WebSocket.waitForFrameReceived(callback);
WebSocket.waitForFrameReceived(callback, options);
Arguments
-
options
WebSocket.WaitForFrameReceivedOptions
(optional)-
setPredicate
Predicate<WebSocketFrame> (optional) Added in: v1.9#Receives the WebSocketFrame object and resolves to truthy value when the waiting should resolve.
-
setTimeout
double (optional) Added in: v1.9#Maximum time to wait for in milliseconds. Defaults to
30000
(30 seconds). Pass0
to disable timeout. The default value can be changed by using the BrowserContext.setDefaultTimeout().
-
-
callback
Runnable Added in: v1.9#Callback that performs the action triggering the event.
Returns
waitForFrameSent
Added in: v1.10Performs action and waits for a frame to be sent. If predicate is provided, it passes WebSocketFrame value into the predicate
function and waits for predicate(webSocketFrame)
to return a truthy value. Will throw an error if the WebSocket or Page is closed before the frame is sent.
Usage
WebSocket.waitForFrameSent(callback);
WebSocket.waitForFrameSent(callback, options);
Arguments
-
options
WebSocket.WaitForFrameSentOptions
(optional)-
setPredicate
Predicate<WebSocketFrame> (optional) Added in: v1.9#Receives the WebSocketFrame object and resolves to truthy value when the waiting should resolve.
-
setTimeout
double (optional) Added in: v1.9#Maximum time to wait for in milliseconds. Defaults to
30000
(30 seconds). Pass0
to disable timeout. The default value can be changed by using the BrowserContext.setDefaultTimeout().
-
-
callback
Runnable Added in: v1.9#Callback that performs the action triggering the event.
Returns
Events
onClose(handler)
Added before v1.9Fired when the websocket closes.
Usage
WebSocket.onClose(handler)
Event data
onFrameReceived(handler)
Added in: v1.9Fired when the websocket receives a frame.
Usage
WebSocket.onFrameReceived(handler)
Event data
onFrameSent(handler)
Added in: v1.9Fired when the websocket sends a frame.
Usage
WebSocket.onFrameSent(handler)
Event data
onSocketError(handler)
Added in: v1.9Fired when the websocket has an error.
Usage
WebSocket.onSocketError(handler)
Event data