Playwriter.Server.Discovery (Playwriter v0.1.0)

Copy Markdown View Source

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_endpoint(endpoint, opts \\ [])

@spec check_endpoint(
  String.t(),
  keyword()
) :: :ok | {:error, term()}

Check if a specific endpoint is reachable.

Examples

:ok = Discovery.check_endpoint("ws://localhost:3337/")
{:error, :econnrefused} = Discovery.check_endpoint("ws://localhost:9999/")

discover(opts \\ [])

@spec discover(keyword()) :: {:ok, String.t()} | {:error, :not_found}

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])

get_wsl2_host_ip()

@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.

hosts()

@spec hosts() :: [String.t()]

Get list of candidate hosts.

Returns hosts in order of preference:

  1. localhost
  2. 127.0.0.1
  3. WSL2 host IP (from /etc/resolv.conf)
  4. host.docker.internal