🎭 Playwright for Rust

crates.io MIT

API reference

Playwright is a rust library to automate Chromium, Firefox and WebKit built on top of Node.js library.

Installation

[dependencies] playwright = "0.0.2"

Usage

```rust use playwright::Playwright;

[tokio::main]

async fn main() -> Result<(), playwright::Error> { envlogger::init(); let mut playwright = Playwright::initialize().await?; // if drop all resources are disposed playwright.prepare()?; // install browsers let mut chromium = playwright.chromium(); let mut browser = chromium.launcher().headless(true).launch().await?; let mut context = browser.contextbuilder().build().await?; let mut page = context.newpage().await?; page.gotobuilder("https://example.com/").goto().await?;

// Exec in browser and Deserialize with serde
let s: String = page.eval("() => location.href").await?;
assert_eq!(s, "https://example.com/");
page.click_builder("a").click().await?;
Ok(())

} ```

It's still under development and has limited functions. Please have a look at tests and docs.rs. Welcome contributions.

Async runtimes

Incompatibility

Functions do not have default arguments in rust. Functions with two or more optional arguments are now passed with the builder pattern.

Playwright Driver

Playwright is designed as a server-client. All playwright client dependent on the driver: zip of core js library and Node.js. Application uses this library will be bundled the driver into rust binary at build time. There is an overhead of unzipping on the first run.

Browser automation in rust

Other languages