Search code examples
playwright

Detect errors on a page loaded using Page.goto


I would typically report a failed test when any of the following errors are reported after loading a page:

  • missing resources (javascript, stylesheet, ...)
  • any javascript exceptions
  • any console.error

I was wondering how to detect "errors" on a page that has been loaded using Page.goto in Playwright?


Solution

  • You will need to attach to some events and evaluate the incoming data:

    • Missing resources: Attach to the response event and check the response.status() value.
    • Javascript exceptions: Attach to the pageerror event.
    • Console error: Attach to the console event and filter messages where type() is error.