# `Playwriter.Server.Discovery`
[🔗](https://github.com/nshkrdotcom/playwriter/blob/v0.1.0/lib/playwriter/server/discovery.ex#L1)

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.

# `check_endpoint`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
