Method: Playwright::BrowserContext#route_web_socket

Defined in:
lib/playwright_api/browser_context.rb

#route_web_socket(url, handler) ⇒ Object

This method allows to modify websocket connections that are made by any page in the browser context.

Note that only ‘WebSocket`s created after this method was called will be routed. It is recommended to call this method before creating any pages.

Usage

Below is an example of a simple handler that blocks some websocket messages. See ‘WebSocketRoute` for more details and examples.

“‘python sync def message_handler(ws: WebSocketRoute, message: Union[str, bytes]):

if message == "to-be-blocked":
  return
ws.send(message)

def handler(ws: WebSocketRoute):

ws.route_send(lambda message: message_handler(ws, message))
ws.connect()

context.route_web_socket(“/ws”, handler) “‘

Raises:

  • (NotImplementedError)


336
337
338
# File 'lib/playwright_api/browser_context.rb', line 336

def route_web_socket(url, handler)
  raise NotImplementedError.new('route_web_socket is not implemented yet.')
end