From d6ef9fb8b6e2e2caf8be397d0d39e7603523e62b Mon Sep 17 00:00:00 2001 From: Sebastian Sebbie Silbermann Date: Fri, 13 Mar 2026 13:42:38 +0100 Subject: [PATCH] [test] Show decoded binary WebSocket messages in traces --- test/lib/browsers/playwright.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/lib/browsers/playwright.ts b/test/lib/browsers/playwright.ts index a65d40ed66ec..cca74133c8a0 100644 --- a/test/lib/browsers/playwright.ts +++ b/test/lib/browsers/playwright.ts @@ -318,15 +318,17 @@ export class Playwright { } page.on('websocket', (ws) => { + const decoder = tracePlaywright ? new TextDecoder() : null if (tracePlaywright) { - page - .evaluate(`console.log('connected to ws at ${ws.url()}')`) - .catch(() => {}) + // We're just evaluating a string here so that it appears in Playwright + // traces. + // console.log spams CI logs. If you already have a browser open, you can + // see WebSocket messages in the network tab of dev tools. + // TODO: Revisit once https://github.com/microsoft/playwright/issues/10996 is resolved. + page.evaluate(`'connected to ws at ${ws.url()}'`).catch(() => {}) ws.on('close', () => - page - .evaluate(`console.log('closed websocket ${ws.url()}')`) - .catch(() => {}) + page.evaluate(`'closed websocket ${ws.url()}'`).catch(() => {}) ) } ws.on('framereceived', (frame) => { @@ -337,7 +339,7 @@ export class Playwright { page // Note that passing the payload as a an argument is 2 orders of magnitude more expensive in Playwright. .evaluate( - `console.log('received ws message ${JSON.stringify(payload)}')` + `'received ws message ${JSON.stringify(typeof payload === 'string' ? payload : decoder!.decode(payload))}'` ) .catch(() => {}) }