TOPIC 41/6018 MINNOT STARTED

Listening to the page: console messages, page errors and events

Listen to what the page says in its console and what breaks inside it, and make the test fail when the page shouts, even if every click works.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: a smoke alarm that tells you which room. A smoke alarm does not put out a fire. It makes a loud noise so that you know. A good one also says the room: kitchen. Without it, a fire can burn behind a closed door while you sit calmly in the lounge.

Tom tests Daily List, a to-do list app. A test can click and check, and all of it can pass, while the page quietly breaks something behind the scenes.

What it is: Playwright is a free tool, made by Microsoft, that opens real web browsers and drives them from test code. This topic is one small slice of it: listening to what the page says while the test runs. A page writes notes to a hidden window called the console. It can also hit errors that nobody sees on screen. Playwright can listen for both and hand them to the test. Do not mix up two consoles. The page has one, and your terminal has another.

Each shout is an event, which is something the page announces. Tom adds an , a small piece of code that runs when a named event happens. It is built into Playwright, so there is nothing extra to install.

Why it matters: without a listener, Tom's test stays green while a stops tasks from saving. Lily finds it after the release. With a listener, the same test fails on the day the fault appears, and the failure names the message.

The picture has limits. An alarm can sound for burnt toast, and a page can write harmless notes too. Tom must decide which shouts matter, or the team learns to ignore the alarm.

Kept simple: this lesson covers the console, page errors and a few other events. The page announces many more.

(SYNTHETIC / TRAINING ONLY: Daily List and every person named in this lesson are invented.)

PLAIN WORDS · 1 in this section
playwright
a free Microsoft tool that drives a browser for tests

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB Listening to what the page shouts in its console and what breaks inside it, and failing the test when it does.

  1. Listen
  2. Load
  3. Act
  4. Check the list
Fit the alarm before the fire

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
A smoke alarmAn event listener
The loud noiseThe console message or page error
The name of the roomThe text and place in the message
Fitting the alarm before the fireAdding the listener before the first load

WHERE THIS PICTURE STOPS

  • An alarm is fitted once in a house, but a listener is added in every test.
  • An alarm cannot tell burnt toast from a fire, and Tom must filter the noise.
  • A fire is always bad, while a console warning may be fine.

HOOK

Fit the alarm first, then light the stove.

REMEMBER IT THIS WAY

A sequence: the real steps, in order.

Fit the alarm first. Add the listener before the first load, then say which room: text and place.

What each part of the trick stands for
In the trickWhat it stands for
alarman event listener
roomthe text and place in the message

A console warning may be fine, so filter the noise before failing a test.

TELL A FRIEND

A listener is a smoke alarm. It must be fitted before the page loads, and it says which room.

OFTEN MIXED UP WITH Reading logs for testers. The earlier lesson shows how to read the logs of a system after a test. This lesson collects the page's own messages while the test runs.

Sources & standards — 5 sources
  1. Market practice

    Page (Playwright documentation) ↗ — Microsoft (Playwright) · The Page class emits events that can be handled with on, once and removeListener; console gives a ConsoleMessage, pageerror reports an uncaught exception, and page.pageErrors() returns recent page errors (search excerpt, page not opened)

    Covers page.routeFromHAR() with its update and notFound options, the popup event, page.waitForLoadState(), page.close() with runBeforeUnload, and page.bringToFront(). Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Market practice

    ConsoleMessage class reference (Playwright documentation) ↗ — Microsoft (Playwright) · ConsoleMessage objects arrive through the page console event, and each has a type and a text (search excerpt, page not opened)

    Says ConsoleMessage objects arrive through the page console event, and gives the type and text of each message. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  3. Market practice

    BrowserContext (Playwright documentation) ↗ — Microsoft (Playwright) · The weberror event on a context reports exceptions that are not handled in any page, and points to pageerror for one page (search excerpt, page not opened)

    Describes context.grantPermissions(), context.clearPermissions(), context.setGeolocation() and the advice to grant the geolocation permission as well as setting a position. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  4. Market practice

    Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Tests should check what users see and should be isolated from each other (search excerpt, page not opened)

    Recommends user-facing locators such as role-based ones over Cascading Style Sheets (CSS) or XPath, web-first assertions that retry, and avoiding fixed waits. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).

  5. Market practice

    Page (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: pause, route/HAR/WebSocket and waitForResponse. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes routeFromHAR and its notFound and update options. Vendor documentation, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: pause, route/HAR/WebSocket and waitForResponse. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

PRACTISE AND KEEP

Sources for this topic — 5 sources
  1. Market practice

    Page (Playwright documentation) ↗ — Microsoft (Playwright) · The Page class emits events that can be handled with on, once and removeListener; console gives a ConsoleMessage, pageerror reports an uncaught exception, and page.pageErrors() returns recent page errors (search excerpt, page not opened)

    Covers page.routeFromHAR() with its update and notFound options, the popup event, page.waitForLoadState(), page.close() with runBeforeUnload, and page.bringToFront(). Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Market practice

    ConsoleMessage class reference (Playwright documentation) ↗ — Microsoft (Playwright) · ConsoleMessage objects arrive through the page console event, and each has a type and a text (search excerpt, page not opened)

    Says ConsoleMessage objects arrive through the page console event, and gives the type and text of each message. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  3. Market practice

    BrowserContext (Playwright documentation) ↗ — Microsoft (Playwright) · The weberror event on a context reports exceptions that are not handled in any page, and points to pageerror for one page (search excerpt, page not opened)

    Describes context.grantPermissions(), context.clearPermissions(), context.setGeolocation() and the advice to grant the geolocation permission as well as setting a position. Vendor documentation for one tool. Practitioner or vendor guidance, not a standard. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  4. Market practice

    Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Tests should check what users see and should be isolated from each other (search excerpt, page not opened)

    Recommends user-facing locators such as role-based ones over Cascading Style Sheets (CSS) or XPath, web-first assertions that retry, and avoiding fixed waits. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).

  5. Market practice

    Page (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: pause, route/HAR/WebSocket and waitForResponse. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Describes routeFromHAR and its notFound and update options. Vendor documentation, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: pause, route/HAR/WebSocket and waitForResponse. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.