Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To capture browser logs in Playwright, attach listeners before the navigation or action you want to diagnose. Use page.on('console') for JavaScript console messages, page.on('pageerror') for uncaught page exceptions, page.on('response') for HTTP status codes, and page.on('requestfailed') for requests that fail to obtain an HTTP response. These are separate event types: a 404 response is not, by itself, a requestfailed event.

Capture console messages, exceptions, and network outcomes on one page

The following Node.js example uses Playwright’s event APIs. Register the listeners before page.goto() so they can observe messages and requests produced during navigation. Keep the page URL and a timestamp with each entry if you plan to save or compare logs later.

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();

  page.on('console', async msg => {
    const values = [];
    for (const arg of msg.args()) {
      try {
        values.push(await arg.jsonValue());
      } catch {
        values.push(msg.text());
      }
    }
    console.log(JSON.stringify({
      kind: 'console',
      type: msg.type(),
      text: msg.text(),
      values,
      pageUrl: page.url(),
      capturedAt: new Date().toISOString()
    }));
  });

  page.on('pageerror', error => {
    console.error(JSON.stringify({
      kind: 'pageerror',
      message: error.message,
      stack: error.stack,
      pageUrl: page.url(),
      capturedAt: new Date().toISOString()
    }));
  });

  page.on('response', response => {
    if (response.status() >= 400) {
      console.error(JSON.stringify({
        kind: 'http',
        status: response.status(),
        url: response.url(),
        pageUrl: page.url(),
        capturedAt: new Date().toISOString()
      }));
    }
  });

  page.on('requestfailed', request => {
    console.error(JSON.stringify({
      kind: 'requestfailed',
      url: request.url(),
      error: request.failure()?.errorText,
      pageUrl: page.url(),
      capturedAt: new Date().toISOString()
    }));
  });

  try {
    await page.goto('https://example.com', { waitUntil: 'load' });
    // Run the interaction under investigation here, if any.
  } finally {
    await browser.close();
  }
})();

Replace the example URL and place the action under investigation after navigation. If an event handler performs asynchronous work, as the console handler does while reading argument values, preserve or await that work if your application needs a guarantee that every formatted record is complete before shutdown. Playwright emits the event; it does not automatically write these records to a file or keep an unlimited archive for you.

Console messages: console

page.on('console') receives a ConsoleMessage for browser console calls such as log, debug, info, warn, and error. Use msg.type() to classify the message and msg.text() for its rendered text. The message also exposes arguments through msg.args(); each argument can be read with jsonValue(), as in the example. Some values may not serialize as ordinary JSON, so retaining msg.text() as a fallback is useful.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Console messages are not all errors. Filter on types such as error or warning only when that matches the purpose of the test; otherwise you may discard diagnostic information. See the Playwright Page API for the current event and message methods.

Uncaught exceptions: pageerror

page.on('pageerror') reports uncaught exceptions in page code. Record at least error.message; include error.stack when available to retain the browser-side call context. A page exception and a console.error message are different signals: use both listeners if you need to capture both categories.

HTTP responses versus failed requests

Use response to inspect HTTP status codes, including 4xx and 5xx responses. Use requestfailed when a request fails without obtaining an HTTP response, for example because of a network failure. Playwright documents the usual successful request lifecycle as request, response, then requestfinished. A network failure may produce requestfailed instead of requestfinished, and may happen instead of a response.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

As the Playwright Request API explains, “HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete with page.on(‘requestfinished’) event and not with page.on(‘requestfailed’).” That distinction is why the example has separate response and request-failure handlers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose page listeners, context listeners, or stored history

Need Use Scope or limitation
Capture a live stream from one page page.on('console'), page.on('pageerror'), page.on('response'), and page.on('requestfailed') Attach before the event of interest; format or persist events yourself.
Cover multiple pages in one browser context Context-level console, web-error, and request/response listeners Context listeners provide broader scope for pages in that context. Context console is documented from v1.34 and weberror from v1.38.
Read recent messages after an action page.consoleMessages() and page.pageErrors() Added in v1.56; current docs describe a bounded history of up to 200 recent entries. They are not an unlimited log.
Keep messages from after a navigation or clear stored console messages Since-navigation filtering and console-message clearing methods Documented from v1.59. Confirm the installed Playwright version before relying on them.
Understand a test failure in its action context Playwright Test tracing and Trace Viewer Trace artifacts relate logs and network activity to actions, snapshots, and the test timeline.

Version numbers above are Playwright API introduction notes, not a guarantee that every project has those methods available. Check the installed package’s version and the documentation for that version before using newer conveniences.

One page or all pages in a context

Page listeners are the direct choice when the test owns a single page and you want to associate events with that page. Browser-context listeners are useful when a flow opens popups or additional tabs and you need broader coverage. Context-level console events are documented as added in v1.34; context-level weberror events for unhandled page exceptions are documented from v1.38. See the BrowserContext API.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

For a popup whose very first request matters, do not wait until the popup’s page event to begin network observation: its request may already have started. Playwright’s documentation advises using browser-context request listeners or routing when observation must begin before that first popup request.

Event stream or bounded history

Listeners are appropriate for continuous capture, custom output, and immediate assertions. The newer page history methods are convenient when you want to inspect recent messages after an action without building your own in-memory collector. The current documentation describes up to 200 recent console messages or page errors; treat that as a bounded convenience buffer, not an archival guarantee. These methods were added in v1.56. Console clearing and filtering messages since navigation are documented from v1.59.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Capture logs for Playwright Test failures with a trace

For an intermittent test failure, raw log lines often lack the action context needed to explain what the page was doing. A Playwright Test trace can include actions, snapshots, console messages, errors, and network information, with a timeline that helps connect an event to the step that preceded it. Configure tracing through Playwright Test when you want the fuller test diagnostic, including assertions.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

After producing a trace artifact, open it in Trace Viewer using the documented workflow. The viewer lets you inspect test actions and their associated browser evidence rather than relying only on terminal output. See Trace Viewer and Debugging Tests.

The lower-level context.tracing API can capture browser operations and network activity, but it does not record Playwright Test assertions. For that reason, use Playwright Test’s trace configuration for test-level diagnostics. The distinction is documented in the Tracing API.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Debug interactively when the failing step is unclear

When you do not yet know which action triggers a message, Playwright Inspector and UI Mode can help you step through a test and inspect logs or network details interactively. They complement event listeners and exported traces: interactive debugging helps explore a failure, while listeners create a deliberately managed log stream and traces preserve diagnostic context for later review. See UI Mode and Debugging Tests.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Common capture problems and fixes

  • No messages appear for navigation: the listener was attached after page.goto() or after the triggering action. Move listener registration earlier.
  • A 404 does not appear under requestfailed: that is expected for an HTTP response. Capture response and inspect response.status() for 4xx or 5xx outcomes.
  • A browser console error is missing from exception logs: console and pageerror represent different event categories. Attach both if you need both console calls and uncaught exceptions.
  • Logs disappear when the test ends: event listeners do not persist output automatically. Write records to your chosen logger or test artifact, and ensure asynchronous formatting has finished before closing the browser.
  • A popup’s first network request is absent: observation may have started only after the popup page was created. Use context-level request listeners or routing when capture must cover the earliest request.
  • consoleMessages() or pageErrors() is undefined: check the installed Playwright version. These page methods were added in v1.56; do not assume a project uses the current documentation version.
  • A trace lacks test assertions: lower-level context tracing does not record Playwright Test assertions. Configure tracing through Playwright Test for fuller test diagnostics.

Or skip the browser setup

If the task is to produce a clean website screenshot rather than debug browser-side logs, ScreenshotNeo is a website screenshot API and MCP server. It does not replace Playwright’s console, exception, or trace diagnostics. A single GET request can return an image or PDF; for example, this cURL call saves a WebP screenshot. See the ScreenshotNeo API documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status with headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month, with no card required.

Frequently Asked Questions

Do Playwright console events include messages from every browser developer-tools panel?

No. The documented page and context APIs capture their corresponding Playwright events; they are not a general export of every message visible in browser developer tools.

Can I use Playwright logs to diagnose a website screenshot that is blank?

Playwright logs can help diagnose browser behavior when you control the browser session. For a screenshot-only workflow, ScreenshotNeo reports page verdict and billing information in response headers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.