Playwright + Java · Lesson 25 of 38
Module 25: Browser Events
Your task
Implement registerConsoleErrorTracker:
Write it in the editor, then press Check answer (Ctrl + Enter).
page.onPageError(error -> {
System.err.println("Client JS Exception: " + error);
});
page.onConsoleMessage(msg -> {
if ("error".equals(msg.type())) {
System.err.println("Console Error: " + msg.text());
}
});Playwright allows you to listen to internal browser events in real time. In this lesson, you will capture browser console errors, unhandled JavaScript exceptions, network requests, and WebSocket messages during test execution. Let's inspect browser events!
Part of the Playwright + Java course (Playwright with Java). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Yes! Storing console messages in a list and asserting errorLogs.isEmpty() in an afterEach hook is a great QA practice to catch client regressions.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___