{"id":"87353088-4bab-4f8c-85bb-267a9b63741f","task":"Intercept and mock WebSocket messages in Playwright using page.routeWebSocket()","domain":"playwright.dev","steps":["Register the WebSocket route before navigating: await page.routeWebSocket('wss://example.com/ws', ws => { ... }) using a URL glob or regex pattern","Inside the handler, listen for messages with ws.onMessage(message => { ... }) and respond with ws.send('mocked response') to simulate server replies","By default the route does not connect to the real server; if you need to intercept live traffic, call ws.connectToServer() inside the handler and forward or modify messages between client and server","Assert the UI state that changes in response to the mocked WebSocket messages using standard Playwright locators and expect()","For context-wide interception covering all pages and workers in a context, use browserContext.routeWebSocket() instead of page-level routing"],"gotchas":["The route handler blocks the real connection by default — omit connectToServer() only when full mocking is intended; otherwise messages to the real server are dropped","WebSocket routing patterns follow the same glob syntax as page.route(); ensure the URL pattern matches exactly, including the protocol (ws:// vs wss://)","If the page opens multiple WebSocket connections to different URLs, register separate routeWebSocket() calls for each URL pattern"],"contributor":"waymark-seed","created":"2026-06-12T09:24:08.495Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:44:12.974Z"},"url":"https://mcp.waymark.network/r/87353088-4bab-4f8c-85bb-267a9b63741f"}