new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Playwright · API reference · all subjects

websocketroute/methods

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

WebSocketRoute.connectToServer method

connectToServer() is a method that returns a WebSocketRoute instance representing the server-side connection. It connects to the actual WebSocket server and allows sending and receiving messages from the server. Once connected, messages from the server are automatically forwarded to the page WebSocket unless onMessage is called on the server-side route. Messages sent by WebSocket.send() in the page are automatically forwarded to the server unless onMessage is called on the original route.

WebSocketRoute.onMessage method

onMessage(handler) is a method that allows handling messages sent by the WebSocket, either from the page or from the server. When called on the original route, it handles messages from the page. Once this method is called, messages are not automatically forwarded—you must handle them manually by calling send(). Calling this method again overrides the previous handler. In JavaScript and Python, the handler receives a string message. In Java and C#, the handler receives a WebSocketFrame.

WebSocketRoute.onClose method

onClose(handler) is a method that allows handling WebSocket.close events. By default, closing one side of the connection closes the other side automatically. When an onClose handler is set up, automatic forwarding of closure is disabled and the handler must take care of it. In JavaScript and Python, the handler receives an optional close code (int or undefined) and an optional close reason (string or undefined). In Java, it receives optional close code (null or int) and close reason (null or string). In C#, it receives nullable int for code and nullable string for reason.

WebSocketRoute.send method

send(message) is a method that sends a message to the WebSocket. When called on the original WebSocket route, it sends the message to the page. When called on the result of connectToServer(), it sends the message to the server. The message parameter is of type string or Buffer.

WebSocketRoute.close method

close() is an async method that closes one side of the WebSocket connection. It accepts two optional parameters: code (int) which is an optional close code, and reason (string) which is an optional close reason. Available since v1.48.

WebSocketRoute.url method

url() is a method that returns the URL of the WebSocket created in the page as a string. Available since v1.48.

WebSocketRoute.protocols method

protocols() is a method available since v1.60 that returns an array of strings representing the list of WebSocket subprotocols requested by the page, as passed via the second argument to the WebSocket constructor. Corresponds to the Sec-WebSocket-Protocol request header. Returns an empty array if no protocols were specified.

Give your agent this brain