sincecutoff.com
← all changes

Playwright WebSocket routes expose requested protocols

Introduced 2026-05-11 · score 0.96

HOW TO USE IT

When handling a routed WebSocket, call `ws.protocols()` to inspect the subprotocols requested by the page; it returns an empty array if none were specified.

await page.routeWebSocket('wss://example.com/ws', ws => { const requestedProtocols = ws.protocols(); });

WHY THIS HELPS

Inspect the subprotocols requested by a page when handling a WebSocket route.

REQUIREMENTS AND LIMITATIONS

  • Version: v1.60.0
  • webSocketRoute.protocols() (required): No arguments; returns the requested subprotocols as an array of strings, or an empty array when none were specified.
  • page.routeWebSocket(url, handler) (required): Sets up the WebSocket route whose handler receives the WebSocketRoute; replace the example URL with the target WebSocket URL or pattern.
  • Prerequisite: Use Playwright v1.60 or later; `WebSocketRoute.protocols()` was added in v1.60.

FIRST-PARTY EVIDENCE

Check the installed version and the source before using it. Entry JSON

Report a problem with this card