October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Log Network Requests with Puppeteer

Attach Puppeteer request and response listeners before navigation, distinguish HTTP error statuses from failed requests, and keep interception off when you only need logs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To log page requests and responses in Puppeteer, attach request, response, and optionally requestfailed listeners before calling page.goto(). Log response status codes as well as URLs: an HTTP 404 or 503 is still a received response, not a failed network request.

Log requests and responses before navigation

Puppeteer’s Network logging guide documents page events for observing requests and responses. Register the listeners before navigation so you can capture the initial document request and early subresources. This runnable ES-module example prints the HTTP method and URL for each request, the status and URL for each response, and available failure details:

As an Amazon Associate I earn from qualifying purchases.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();

  page.on('request', request => {
    console.log('→', request.method(), request.url());
  });

  page.on('response', response => {
    console.log('←', response.status(), response.url());
  });

  page.on('requestfailed', request => {
    const failure = request.failure();
    console.error('×', request.url(), failure?.errorText ?? 'failure text unavailable');
  });

  await page.goto('https://example.com');
} finally {
  await browser.close();
}

The example uses Puppeteer’s page events and request/response objects; it is not a claim of a test run. See the Puppeteer Network logging guide and the HTTPRequest API reference.

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

Understand the request lifecycle

  • request fires when the page issues a request.
  • response fires when a response arrives. The response event gives you the status and URL to log.
  • requestfinished fires after the response body is downloaded and the request completes.
  • requestfailed is emitted when the request fails instead of completing with requestfinished. Its failure() result can be null, and error text may be unavailable, so guard both.

An HTTP error status is not the same as a transport failure. A server response with status 404 or 503 normally still follows the response and request-finished path; it does not, by itself, trigger requestfailed. Log response.status() to identify HTTP errors. See HTTPRequest.failure() and the PageEvent reference.

Redirects also create multiple log entries: the request that receives a redirect response finishes, then the browser issues a new request to the redirected URL. Treat the resulting URLs as a chain of requests rather than expecting one entry whose URL changes in place.

Choose event logging or interception

Approach Use it for What to account for
Page event logging Observing URLs, methods, response statuses, and request lifecycle events. Listeners report events; they are the simpler choice when you do not need to change traffic.
Request interception Modifying, aborting, continuing, or fulfilling requests. After interception is enabled, requests can stall until resolved (unless completed using the browser cache). Handlers must reliably resolve requests and account for requests already handled by another handler.

For logging alone, leave interception off. The Puppeteer Request Interception guide explains the extra handling required when controlling traffic; the Page.setRequestInterception() API documents the setting.

Filter output and remove listeners cleanly

Request objects expose properties such as URL, method, headers, post data, and resource type. Filter inside the event callback when you only need a host or resource category, rather than printing every request. Avoid sending authorization headers, cookies, or sensitive request bodies to shared logs.

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

Use a named callback when the logger should stop before the page closes. Puppeteer’s Page is an event emitter, and its API supports removing listeners:

function logRequest(request) {
  console.log(request.url());
}

page.on('request', logRequest);

// Later, when logging is no longer needed:
page.off('request', logRequest);

See the Puppeteer Page API reference.

Troubleshoot missing or confusing log entries

  • The first page URL is missing: listeners may have been attached after navigation started. Register them before page.goto().
  • A 404 or 503 does not appear under failures: that is expected for an HTTP response. Inspect the response event’s status instead.
  • A failure has no explanation: request.failure() can be null or lack useful text. Keep logging the URL and use a fallback message, as in the example.
  • You see several URLs for one navigation: redirects issue a new request for the destination. Read the entries as a redirect chain.
  • Requests appear to hang after enabling interception: ensure every intercepted request is resolved and check whether another handler already handled it. If the goal is only logging, disable interception and use page events.
  • The log is too noisy or exposes sensitive data: filter by host, method, or resource type and do not print credentials, cookies, authorization headers, or private bodies into shared logs.

What page event logs do not promise

These page listeners are the documented route for observing page requests and responses. The cited Puppeteer references do not establish that this method captures every possible network operation from every browser, worker, or service-worker context, so do not treat the output as a guaranteed exhaustive browser-wide trace.

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

Or skip the browser setup

If you need a rendered screenshot rather than an event-by-event request log, ScreenshotNeo is a website screenshot API with a single GET request. It removes cookie and consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed; an MCP server lets AI agents take screenshots; and 1,000 screenshots per month are free with no card, with paid plans starting at $5 for 3,000.

For API details and options, see the ScreenshotNeo documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

Sign up for 1,000 free screenshots a month, with no card required.

Best Value
The SQL Programming Language: .
  • Used Book in Good Condition

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.