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:Microsoft Playwright NetworkUtils

From Leeroopedia

Template:Implementation Page

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 via SocksProxyAgent and HTTPS proxies via HttpsProxyAgent
  • fetchData -- convenience wrapper for fetching data as string or JSON with progress reporting
  • createHttpServer -- creates an HTTP server with proper connection tracking for clean shutdown
  • startHttpServer -- starts a server and resolves when it begins listening
  • download -- 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

Page Connections

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