Discovers Playwright server endpoints in WSL-to-Windows scenarios.
This module attempts to find a running Playwright server by trying various host/port combinations commonly used in WSL2 environments.
Summary
Functions
Check if a specific endpoint is reachable.
Discover a working WebSocket endpoint.
Get the Windows host IP from WSL2.
Get list of candidate hosts.
Functions
Check if a specific endpoint is reachable.
Examples
:ok = Discovery.check_endpoint("ws://localhost:3337/")
{:error, :econnrefused} = Discovery.check_endpoint("ws://localhost:9999/")
Discover a working WebSocket endpoint.
Tries multiple host/port combinations to find a running Playwright server.
Options
:ports- List of ports to try (default: [3337, 3336, 3335, 3334, 9222]):timeout- Connection timeout in ms (default: 1000):hosts- Override host list (default: auto-detected)
Examples
{:ok, "ws://localhost:3337/"} = Discovery.discover()
{:error, :not_found} = Discovery.discover(ports: [9999])
@spec get_wsl2_host_ip() :: String.t() | nil
Get the Windows host IP from WSL2.
Parses /etc/resolv.conf to find the nameserver, which in WSL2 is typically the Windows host IP.
@spec hosts() :: [String.t()]
Get list of candidate hosts.
Returns hosts in order of preference:
- localhost
- 127.0.0.1
- WSL2 host IP (from /etc/resolv.conf)
- host.docker.internal