Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Is there a way to capture console error logs ? #5546

Closed
vincent-prz opened this issue Feb 22, 2021 · 2 comments
Closed

[Question] Is there a way to capture console error logs ? #5546

vincent-prz opened this issue Feb 22, 2021 · 2 comments

Comments

@vincent-prz
Copy link

I tried to use this setting : https://playwright.dev/docs/api/class-logger?_highlight=log#loggerisenabledname-severity

But it didn't succeed.

Note: we're using QAWolf 1.3.3, with Playwright 1.8.0

@mxschmitt
Copy link
Member

You can do something like that to listen to console.error events: https://playwright.dev/docs/api/class-page/#pageonconsole

// @ts-check
const playwright = require("playwright");

(async () => {
  const browser = await playwright.chromium.launch();
  const context = await browser.newContext();
  const page = await context.newPage();
  const errorLogs = []
  page.on("console", (message) => {
    if (message.type() === "error") {
      errorLogs.push(message.text())
    }
  })
  await page.evaluate(() => {
    console.error("hello from the browser")
  })
  console.log(errorLogs)
  await browser.close();
})();

There is also the pageError event which can be used to catch unhandled exceptions which get thrown inside the browser:

 page.on("pageerror", (err) => {
    console.log(err.message)
  })

Does this fit for your needs?

@vincent-prz
Copy link
Author

The pageerror handler fits our needs perfectly! Thanks @mxschmitt !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants