Unverified Commit 156307e3 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Show decoded binary WebSocket messages in traces (#91308)

parent 236a76dd
...@@ -318,15 +318,17 @@ export class Playwright<TCurrent = undefined> { ...@@ -318,15 +318,17 @@ export class Playwright<TCurrent = undefined> {
} }
page.on('websocket', (ws) => { page.on('websocket', (ws) => {
const decoder = tracePlaywright ? new TextDecoder() : null
if (tracePlaywright) { if (tracePlaywright) {
page // We're just evaluating a string here so that it appears in Playwright
.evaluate(`console.log('connected to ws at ${ws.url()}')`) // traces.
.catch(() => {}) // 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', () => ws.on('close', () =>
page page.evaluate(`'closed websocket ${ws.url()}'`).catch(() => {})
.evaluate(`console.log('closed websocket ${ws.url()}')`)
.catch(() => {})
) )
} }
ws.on('framereceived', (frame) => { ws.on('framereceived', (frame) => {
...@@ -337,7 +339,7 @@ export class Playwright<TCurrent = undefined> { ...@@ -337,7 +339,7 @@ export class Playwright<TCurrent = undefined> {
page page
// Note that passing the payload as a an argument is 2 orders of magnitude more expensive in Playwright. // Note that passing the payload as a an argument is 2 orders of magnitude more expensive in Playwright.
.evaluate( .evaluate(
`console.log('received ws message ${JSON.stringify(payload)}')` `'received ws message ${JSON.stringify(typeof payload === 'string' ? payload : decoder!.decode(payload))}'`
) )
.catch(() => {}) .catch(() => {})
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment