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 HTTPResponse

From Leeroopedia
Revision as of 11:46, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Puppeteer_Puppeteer_HTTPResponse.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Sources packages/puppeteer-core/src/api/HTTPResponse.ts
Domains HTTP Networking, Response Handling, Content Parsing
Last Updated 2026-02-12

Overview

HTTPResponse is the abstract base class that represents HTTP responses received by a Page during navigation and resource loading.

Description

The HTTPResponse class provides a unified interface for inspecting HTTP responses intercepted by Puppeteer. It exposes metadata such as the response URL, HTTP status code and text, response headers (all lower-case), remote address (IP and port), security details for HTTPS connections, and timing information from the CDP Network.ResourceTiming protocol.

The class provides several methods for accessing response body content in different formats: content() returns raw bytes as a Uint8Array, buffer() wraps that in a Node.js Buffer, text() decodes the body as UTF-8 (throwing if the content is not valid UTF-8), and json() parses the text as JSON. The ok() convenience method checks whether the status code falls in the 200-299 range (or is 0).

Additional methods expose the originating HTTPRequest via request(), whether the response was served from cache via fromCache(), whether it was served by a service worker via fromServiceWorker(), and the initiating Frame via frame().

The RemoteAddress interface, also exported from this module, provides an optional ip string and port number for the remote server connection details.

Usage

HTTPResponse instances are not created directly. They are returned by methods such as Page.goto(), Page.waitForResponse(), or accessed through HTTPRequest.response(). Concrete implementations are provided by protocol-specific subclasses (CDP or BiDi).

Code Reference

Source Location

packages/puppeteer-core/src/api/HTTPResponse.ts

Signature

export interface RemoteAddress {
  ip?: string;
  port?: number;
}

export abstract class HTTPResponse {
  abstract remoteAddress(): RemoteAddress;
  abstract url(): string;
  ok(): boolean;
  abstract status(): number;
  abstract statusText(): string;
  abstract headers(): Record<string, string>;
  abstract securityDetails(): SecurityDetails | null;
  abstract timing(): Protocol.Network.ResourceTiming | null;
  abstract content(): Promise<Uint8Array>;
  async buffer(): Promise<Buffer>;
  async text(): Promise<string>;
  async json(): Promise<any>;
  abstract request(): HTTPRequest;
  abstract fromCache(): boolean;
  abstract fromServiceWorker(): boolean;
  abstract frame(): Frame | null;
}

Import

import type {HTTPResponse, RemoteAddress} from 'puppeteer-core/src/api/HTTPResponse.js';

I/O Contract

Inputs

Parameter Type Description
(none) HTTPResponse methods take no parameters; the response data is populated internally by the protocol layer

Outputs

Method Return Type Description
remoteAddress() RemoteAddress IP address and port of the remote server
url() string The URL of the response
ok() boolean True if status is 0 or in 200-299 range
status() number HTTP status code (e.g. 200)
statusText() string HTTP status text (e.g. "OK")
headers() Record<string, string> Response headers (lower-case keys)
securityDetails() null TLS/SSL details or null
timing() null Resource timing data or null
content() Promise<Uint8Array> Raw response body bytes
buffer() Promise<Buffer> Response body as a Node.js Buffer
text() Promise<string> Response body decoded as UTF-8 string
json() Promise<any> Response body parsed as JSON
request() HTTPRequest The matching HTTP request
fromCache() boolean True if served from disk or memory cache
fromServiceWorker() boolean True if served by a service worker
frame() null The frame that initiated this response

Usage Examples

// Navigate and inspect the response
const response = await page.goto('https://example.com');
console.log(response.status()); // 200
console.log(response.ok());     // true
console.log(response.url());    // 'https://example.com/'
// Read response body in different formats
const response = await page.goto('https://api.example.com/data');
const rawBytes = await response.content();
const text = await response.text();
const json = await response.json();
// Inspect response metadata
const response = await page.goto('https://example.com');
const headers = response.headers();
console.log(headers['content-type']);

const remote = response.remoteAddress();
console.log(`Connected to ${remote.ip}:${remote.port}`);

const security = response.securityDetails();
if (security) {
  console.log(`Protocol: ${security.protocol()}`);
}
// Wait for a specific response
const response = await page.waitForResponse(
  res => res.url().includes('/api/data'),
);
const data = await response.json();

Related Pages

Page Connections

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