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 HappyEyeballs

From Leeroopedia

Template:Implementation Page

Overview

HappyEyeballs implements the Happy Eyeballs 2 algorithm (RFC 8305) for dual-stack (IPv4/IPv6) connection establishment, providing HTTP and HTTPS agents that try multiple addresses concurrently for faster connections.

Description

This module provides custom http.Agent and https.Agent implementations that use the Happy Eyeballs algorithm. When connecting to a hostname that resolves to both IPv4 and IPv6 addresses, the algorithm: 1. Performs DNS lookup for both A and AAAA records 2. Starts connecting to the first resolved address 3. After a 300ms delay, starts a parallel connection attempt to the next address family 4. Uses whichever connection succeeds first, closing the other

This matches Chromium's behavior and provides better connection reliability on dual-stack networks.

Usage

The exported agents are used as default HTTP/HTTPS agents throughout Playwright for all outgoing connections.

Code Reference

Source Location

packages/playwright-core/src/server/utils/happyEyeballs.ts (207 lines)

Export Signatures

export const httpsHappyEyeballsAgent: https.Agent;
export const httpHappyEyeballsAgent: http.Agent;
export async function createSocket(host: string, port: number): Promise<net.Socket>;

Import

import { httpHappyEyeballsAgent, httpsHappyEyeballsAgent, createSocket } from './server/utils/happyEyeballs';

I/O Contract

Inputs

  • Standard http.ClientRequestArgs for agent-based connections
  • host: string and port: number for direct socket creation

Outputs

  • net.Socket or tls.TLSSocket connected to the target
  • Automatically selects the fastest responding address

Constants

  • connectionAttemptDelayMs = 300 -- delay before trying the alternate address family

Related Pages

Page Connections

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