Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Puppeteer Puppeteer Cdp HTTPResponse

From Leeroopedia
Property Value
sources packages/puppeteer-core/src/cdp/HTTPResponse.ts
domains CDP, Networking, HTTP
last_updated 2026-02-12 00:00 GMT

Overview

Description

The CdpHTTPResponse class is the CDP-specific implementation of the abstract HTTPResponse base class. It represents an HTTP response received through the Chrome DevTools Protocol's Network domain and provides access to:

  • Response metadata -- Status code, status text, URL, headers, remote address (IP and port), security details, and timing information.
  • Response body -- Lazily fetched via Network.getResponseBody when content() is called; the body loading is deferred until the response body has been fully received (tracked by an internal Deferred).
  • Cache information -- Whether the response was served from disk cache or a service worker.

The constructor accepts the response payload from CDP along with optional "extra info" from the Network.responseReceivedExtraInfo event. When extra info is available, it takes precedence for status code and headers, and the status text is parsed from the raw headers text.

Usage

CdpHTTPResponse instances are created internally by the CDP NetworkManager when responses are received. Users access them through page.on('response') events, request.response(), or navigation methods like page.goto().

Code Reference

Source Location

packages/puppeteer-core/src/cdp/HTTPResponse.ts (168 lines)

Signature

export class CdpHTTPResponse extends HTTPResponse {
  constructor(
    request: CdpHTTPRequest,
    responsePayload: Protocol.Network.Response,
    extraInfo: Protocol.Network.ResponseReceivedExtraInfoEvent | null,
  );

  _resolveBody(err?: Error): void;

  remoteAddress(): RemoteAddress;
  url(): string;
  status(): number;
  statusText(): string;
  headers(): Record<string, string>;
  securityDetails(): SecurityDetails | null;
  timing(): Protocol.Network.ResourceTiming | null;
  content(): Promise<Uint8Array>;
  request(): CdpHTTPRequest;
  fromCache(): boolean;
  fromServiceWorker(): boolean;
  frame(): Frame | null;
}

Import

import { CdpHTTPResponse } from '../cdp/HTTPResponse.js';

I/O Contract

Constructor

Direction Name Type Description
Input request CdpHTTPRequest The corresponding HTTP request
Input responsePayload Protocol.Network.Response CDP response payload with status, headers, timing, security details, etc.
Input extraInfo null Optional extra info providing more accurate status codes and headers

content

Direction Name Type Description
Output result Promise<Uint8Array> The response body as a typed array
Error ProtocolError ProtocolError Thrown if the resource is not found (e.g., preflight requests)

Key accessors

Method Return Type Description
status() number HTTP status code (from extra info if available)
statusText() string HTTP status text (parsed from extra info headers text if available)
headers() Record<string, string> Response headers with lowercase keys
remoteAddress() RemoteAddress Server IP and port
securityDetails() null TLS/SSL security details, or null
timing() null Resource timing data, or null
fromCache() boolean True if served from disk cache or memory cache
fromServiceWorker() boolean True if served by a service worker

Usage Examples

// Listen for HTTP responses
page.on('response', async (response) => {
  console.log(`${response.status()} ${response.url()}`);
  console.log('Headers:', response.headers());
  console.log('Remote address:', response.remoteAddress());

  if (response.status() === 200) {
    const body = await response.content();
    console.log('Body length:', body.length);
  }

  if (response.securityDetails()) {
    console.log('Protocol:', response.securityDetails().protocol());
  }

  console.log('From cache:', response.fromCache());
  console.log('From service worker:', response.fromServiceWorker());
});

// Get response from navigation
const response = await page.goto('https://example.com');
console.log('Status:', response.status());
console.log('Status text:', response.statusText());

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment