# `PlaywrightEx.Driver`
[🔗](https://github.com/ftes/playwright_ex/blob/v0.17.0-rc.5/lib/playwright_ex/driver.ex#L1)

Installs and locates the Playwright driver: a pinned `playwright-core` npm package plus
the pinned Node.js binary for the host platform. No Node.js is needed beforehand.

Mirrors playwright-python (`scripts/build_driver.py`, `_impl/_driver.py`), except that
Python assembles the bundle at wheel-build time and we do it lazily on the user's machine.

Layout (same as Python's `playwright/driver/`):

    <cache_dir>/<driver_version>/<platform>/
      node | node.exe   Node.js binary
      LICENSE           Node.js license
      package/          playwright-core npm package (package/cli.js is the entry point)

`cache_dir` defaults to `:filename.basedir(:user_cache, "playwright_ex")`, overridable with
the `:cache_dir` option or `PLAYWRIGHT_EX_CACHE_DIR`.

Overrides (no download happens when one is set):

  * `executable: path` / `PLAYWRIGHT_EX_EXECUTABLE` - an npm-managed `playwright` CLI
    (e.g. `node_modules/.bin/playwright`), run as `path run-driver`.
  * `node: path` / `PLAYWRIGHT_NODEJS_PATH` - like Python: use this Node binary with the
    cached `package/cli.js` (the package is still installed if missing).

# `option`

```elixir
@type option() ::
  {:executable, Path.t()}
  | {:node, Path.t()}
  | {:cache_dir, Path.t()}
  | {:platform, String.t()}
```

An option, overriding its environment variable (see the module docs). `:platform` (nodejs.org
naming, `"linux-x64"`) installs or locates the driver of another platform than the host's.

# `cache_dir`

```elixir
@spec cache_dir([option()]) :: String.t()
```

The cache directory: the `:cache_dir` option, else `PLAYWRIGHT_EX_CACHE_DIR`, else the user cache
directory (`:filename.basedir(:user_cache, "playwright_ex")`).

# `ensure_installed`

```elixir
@spec ensure_installed([option()]) :: {String.t(), [String.t()]}
```

Installs the driver unless it is installed or an override is set (`install/1`), then returns
`executable/1`. `PlaywrightEx.Supervisor` calls it when it starts.

# `executable`

```elixir
@spec executable([option()]) :: {String.t(), [String.t()]}
```

The driver command: `{program, args_prefix}`, to which `run-driver`, `install ...` etc. are
appended. Doesn't install, see `ensure_installed/1`.

# `install`

```elixir
@spec install([option() | {:force, boolean()}]) :: :ok
```

Downloads, verifies and extracts the driver. Idempotent; atomic (everything happens in a
temp dir next to the target, which is renamed into place only after all checks passed).

Options: `:cache_dir`, `:platform`, `force: true` to reinstall. Raises if a download or a
checksum fails.

# `install_browsers`

```elixir
@spec install_browsers([String.t()], [option()]) ::
  :ok | {:error, {:exit_status, non_neg_integer()}}
```

Installs browsers with the driver's own Node, like `python -m playwright install ...`
(which forwards its argv to `node cli.js`). No args installs its default browsers, as
`npx playwright install`. Browsers land in Playwright's usual
location (`PLAYWRIGHT_BROWSERS_PATH`, default `~/Library/Caches/ms-playwright` etc). The
output goes to stdout; a failed install returns the CLI's exit status.

# `install_dir`

```elixir
@spec install_dir([option()]) :: String.t()
```

Where the pinned driver is (or will be) installed: `<cache_dir>/<version>/<platform>`.

# `installed?`

```elixir
@spec installed?([option()]) :: boolean()
```

Whether the pinned driver is installed in `install_dir/1`.

# `node_version`

```elixir
@spec node_version() :: String.t()
```

The pinned Node.js version the driver runs on (unless `:node` or `:executable` is set).

# `version`

```elixir
@spec version() :: String.t()
```

The pinned Playwright version (`playwright-core` on npm), which the driver runs.

---

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