Skip to main content
Version: 1.17

WebSocket

The WebSocket class represents websocket connections in the page.

webSocket.on('close')

Fired when the websocket closes.

webSocket.on('framereceived')

Fired when the websocket receives a frame.

webSocket.on('framesent')

Fired when the websocket sends a frame.

webSocket.on('socketerror')

Fired when the websocket has an error.

webSocket.isClosed()

Indicates that the web socket has been closed.

webSocket.url()

Contains the URL of the WebSocket.

webSocket.waitForEvent(event[, optionsOrPredicate, options])

  • event <string> Event name, same one would pass into webSocket.on(event).#
  • optionsOrPredicate <function|Object> Either a predicate that receives an event or an options object. Optional.#
    • predicate <function> receives the event data and resolves to truthy value when the waiting should resolve.
    • timeout <number> maximum time to wait for in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout. The default value can be changed by using the browserContext.setDefaultTimeout(timeout).
  • options <Object>
    • predicate <function> Receives the event data and resolves to truthy value when the waiting should resolve.#
  • returns: <Promise<Object>>#

Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value. Will throw an error if the webSocket is closed before the event is fired. Returns the event data value.