Skip to content

Commit

Permalink
fix: log playwright browser download progress on stderr
Browse files Browse the repository at this point in the history
If a browser is downloaded during a test run, playwright will log
on stdout.

This can interfere with the calling code if it's trying to parse
the output of the program as, for example, JSON.

The fix is to temporarily replace `console.log` with `console.error`
as that's what the [logPolitely](https://github.com/microsoft/playwright/blob/718bd9b35fd206245401a9ecb320289f427592d9/packages/playwright-core/src/server/registry/browserFetcher.ts#L120)
function uses to give feedback to the user.

The intention of the playwright maintainers is [not for this
functionality to be used during a test run](microsoft/playwright#32487 (comment))
so it's unlikely to move to stderr otherwise.
  • Loading branch information
achingbrain committed Sep 10, 2024
1 parent 697ce4f commit a95668f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,19 @@ export async function getPw(browserName) {
const api = await import('playwright-core')
const browser = registry.findExecutable(browserName)

await registry.install([browser])
// playwright will log browser download progress to stdout, temporarily
// redirect the output to stderr
const log = console.log
const info = console.info

try {
console.log = console.error
console.info = console.error
await registry.install([browser])
} finally {
console.log = log
console.info = info
}

return api[browserName]
}
Expand Down

0 comments on commit a95668f

Please sign in to comment.