Skip to content

ftes/playwright_ex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hex.pm Version Hex Docs License GitHub Actions Workflow Status

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

  1. Add dependency # mix.exs {:playwright_ex, "~> 0.4"}

  2. Ensure playwright is installed (executable in $PATH or installed via npm)

  3. 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)

  4. 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"
  )

API Layers

Most channel functions are thin protocol wrappers. In ExDoc, composed helpers are grouped under Client-Composed Functions.

References

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:

  1. Check out the repo
  2. Run mix setup. This will take care of setting up your dependencies, installing the JavaScript dependencies (including Playwright), and compiling the assets.
  3. Run mix test or, for a more thorough check that matches what we test in CI, run mix check.
  4. Run mix test.websocket to run all tests against a 'remote' playwright server via websocket. Docker needs to be installed. A container is started via testcontainers.

About

Elixir client for the Playwright node.js server.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages