PlaywrightEx
Elixir client for the Playwright node.js server.
Automate browsers like Chromium, Firefox, Safari and Edge. Helpful for web scraping and agentic AI.
Please get in touch with feedback of any shape and size.
Enjoy!
Freddy.
Getting started
Add dependency
# mix.exs {:playwright_ex, "~> 0.4"}Ensure
playwrightis installed (executable in$PATHor installed vianpm)Start connection (or add to supervision tree)
# if installed via npm or similar add `executable: "assets/node_modules/playwright/cli.js"` {:ok, _} = PlaywrightEx.Supervisor.start_link(timeout: 1000)Use it
alias PlaywrightEx.{Browser, BrowserContext, Frame} {:ok, browser} = PlaywrightEx.launch_browser(:chromium, timeout: 1000) {:ok, context} = Browser.new_context(browser.guid, timeout: 1000) {:ok, %{main_frame: frame}} = BrowserContext.new_page(context.guid, timeout: 1000) {:ok, _} = Frame.goto(frame.guid, "https://elixir-lang.org/", timeout: 1000) {:ok, _} = Frame.click(frame.guid, Selector.link("Install"), timeout: 1000)
Remove server via Websocket
By default, PlaywrightEx launches a local playwright driver.
This is typically installed via npm or bun.
Alternatively, PlaywrightEx can connect to a remote playwright server:
# mix.exs
{:websockex, "~> 0.4"} docker run -p 3000:3000 --rm --init -it \\
mcr.microsoft.com/playwright:v1.58.0-noble \\
npx -y playwright@1.58.0 run-server --port 3000 --host 0.0.0.0 {:ok, _} = PlaywrightEx.Supervisor.start_link(
timeout: 1000,
ws_endpoint: "ws://localhost:3000?browser=chromium"
)References
- Code extracted from phoenix_test_playwright.
- Inspired by playwright-elixir.
- Official playwright node.js client docs.
Comparison to playwright-elixir
playwright-elixir built on the python client and tried to provide a comprehensive client from the start.
playwright_ex instead is a ground-up implementation. It is not intended to be comprehensive. Rather, it is intended to be simple and easy to extend.
Contributing
To run the tests locally, you'll need to:
- Check out the repo
- Run
mix setup. This will take care of setting up your dependencies, installing the JavaScript dependencies (including Playwright), and compiling the assets. - Run
mix testor, for a more thorough check that matches what we test in CI, runmix check. - Run
mix test.websocketto run all tests against a 'remote' playwright server via websocket. Docker needs to be installed. A container is started viatestcontainers.