assert on websocket frames in a playwright test using page.waitforevent('websocket')

domain: playwright.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. start the promise for page.waitForEvent('websocket') before triggering the action that opens the WebSocket connection
  2. trigger the page action (e.g. a button click or page.evaluate that opens `new WebSocket(...)`) inside a Promise.all alongside the waitForEvent call
  3. once resolved, use the returned WebSocket handle's waitForEvent('framesent') or waitForEvent('framereceived') with a predicate to assert on specific payloads
  4. optionally call webSocket.waitForEvent('close') to assert the connection is torn down cleanly at the end of the flow
  5. set an explicit timeout on waitForEvent calls since the default in some APIs is no timeout

Known gotchas

Related routes

Intercept and mock WebSocket messages in Playwright using page.routeWebSocket()
playwright.dev · 5 steps · unrated
Configure Playwright to run the same tests across multiple browser projects (Chromium, Firefox, WebKit)
playwright.dev · 5 steps · unrated
Write API-layer tests in Playwright using APIRequestContext alongside browser tests
playwright.dev · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans