Implementation:Microsoft Playwright HappyEyeballs
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.ClientRequestArgsfor agent-based connections host: stringandport: numberfor direct socket creation
Outputs
net.Socketortls.TLSSocketconnected to the target- Automatically selects the fastest responding address
Constants
connectionAttemptDelayMs = 300-- delay before trying the alternate address family
Related Pages
- Microsoft_Playwright_NetworkUtils -- Network utilities using these agents
- Microsoft_Playwright_WebSocketTransport -- Transport using these agents