Implementation:Microsoft Playwright NetworkUtils
Appearance
Overview
NetworkUtils provides HTTP request utilities, server creation helpers, and proxy configuration for Playwright's outgoing network operations.
Description
This module offers:
httpRequest-- makes HTTP/HTTPS requests with proxy support, timeout, and cancelation. Handles SOCKS proxies viaSocksProxyAgentand HTTPS proxies viaHttpsProxyAgentfetchData-- convenience wrapper for fetching data as string or JSON with progress reportingcreateHttpServer-- creates an HTTP server with proper connection tracking for clean shutdownstartHttpServer-- starts a server and resolves when it begins listeningdownload-- downloads files with progress reporting and hash verification- HTTP/2 server creation utilities for client certificate testing
Usage
Used throughout Playwright for browser downloads, API request context, and internal server creation.
Code Reference
Source Location
packages/playwright-core/src/server/utils/network.ts (257 lines)
Key Signatures
export type HTTPRequestParams = {
url: string;
method?: string;
headers?: http.OutgoingHttpHeaders;
data?: string | Buffer;
rejectUnauthorized?: boolean;
socketTimeout?: number;
};
export const NET_DEFAULT_TIMEOUT = 30_000;
export function httpRequest(params: HTTPRequestParams, onResponse: (r: http.IncomingMessage) => void, onError: (error: Error) => void): { cancel(error: Error | undefined): void };
export function fetchData(params: HTTPRequestParams, ...): Promise<string>;
export function createHttpServer(handler: (req: http.IncomingMessage, res: http.ServerResponse) => void): http.Server;
export async function startHttpServer(server: http.Server, ...): Promise<string>;
Import
import { httpRequest, fetchData, createHttpServer, NET_DEFAULT_TIMEOUT } from './server/utils/network';
I/O Contract
Inputs
- URL, method, headers, body data for HTTP requests
- Proxy configuration auto-detected from environment
Outputs
- HTTP response objects or parsed response data
- Server instances listening on specified ports
Related Pages
- Microsoft_Playwright_HappyEyeballs -- HTTP agents for dual-stack connections
- Microsoft_Playwright_HttpServer -- Higher-level HTTP server with routing
- Microsoft_Playwright_WsServer -- WebSocket server using network utilities
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment