Skip to content

padamson/playwright-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

146 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Playwright for Rust

crates.io docs.rs CI License Playwright

Rust language bindings for Microsoft Playwright β€” the industry standard for cross-browser end-to-end testing.

Status: Pre-1.0, API stabilizing. See coverage trajectory for the path to v1.0.

🎯 Why playwright-rust?

Read our WHY.md to understand the vision, timing, and philosophy behind this project.

TL;DR: Rust is emerging as a serious web development language, with frameworks like Axum and Actix gaining traction. AI coding assistants are making Rust accessible to more developers. Test-Driven Development is experiencing a renaissance as the optimal way to work with AI agents. These trends are converging now, and they need production-quality E2E testing. playwright-rust fills that gap by bringing Playwright's industry-leading browser automation to the Rust ecosystem.

Roadmap and Goals

See Development Roadmap for plans and status of the development approach for playwright-rust.

Goal: Build this library to a production-quality state for broad adoption as @playwright/rust or playwright-rs. Provide official-quality Rust bindings for Microsoft Playwright, following the same architecture as playwright-python, playwright-java, and playwright-dotnet.

Quick Comparison: Python vs Rust

The API matches Playwright's cross-language conventions β€” if you know playwright-python, you know playwright-rust:

PythonRust
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto("https://example.com")

    # Locator with auto-waiting
    heading = page.locator("h1")
    assert heading.text_content() == "Example Domain"

    # Response body access
    resp = page.goto("https://api.example.com/data")
    data = resp.json()

    browser.close()
use playwright_rs::Playwright;

let pw = Playwright::launch().await?;
let browser = pw.chromium().launch().await?;
let page = browser.new_page().await?;
page.goto("https://example.com", None).await?;

// Locator with auto-waiting
let heading = page.locator("h1").await;
assert_eq!(heading.text_content().await?, Some("Example Domain".into()));

// Response body access
let resp = page.goto("https://api.example.com/data", None).await?.unwrap();
let data: serde_json::Value = resp.json().await?;

browser.close().await?;

Coverage Trajectory

Each pre-v1.0 release targets 100% coverage of specific API classes:

Class Methods Current (v0.9) v0.10.0 v0.11.0
Locator 55 100% 100% 100%
Response 18 100% 100% 100%
Request 19 100% 100% 100%
Page 67 ~81% ~90% 100%
BrowserContext 32 ~66% 100% 100%
Frame 29 ~38% 100% 100%
FrameLocator 10 0% 100% 100%

Bold = release where the class reaches 100%. See the full gap analysis for details.

How It Works

playwright-rust follows Microsoft's proven architecture for language bindings:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ playwright-rs (Rust API)                     β”‚
β”‚ - High-level, idiomatic Rust API             β”‚
β”‚ - Async/await with tokio                     β”‚
β”‚ - Type-safe bindings                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚ JSON-RPC over stdio
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Playwright Server (Node.js/TypeScript)       β”‚
β”‚ - Browser automation logic                   β”‚
β”‚ - Cross-browser protocol abstraction         β”‚
β”‚ - Maintained by Microsoft Playwright team    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚ Native protocols
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β–Ό             β–Ό             β–Ό
    Chromium      Firefox       WebKit

This means:

  • βœ… Full feature parity with Playwright (JS/Python/Java/.NET)
  • βœ… Cross-browser support (Chromium, Firefox, WebKit)
  • βœ… Automatic updates when Playwright server updates
  • βœ… Minimal maintenance - protocols handled by Microsoft's server
  • βœ… Production-tested architecture used by millions

API Design Philosophy

Following Playwright's cross-language consistency:

  1. Match Playwright API exactly - Same method names, same semantics
  2. Idiomatic Rust - Use Result, async/await, builder patterns where appropriate
  3. Type safety - Leverage Rust's type system for compile-time safety
  4. Auto-waiting - Built-in smart waits like other Playwright implementations
  5. Testing-first - Designed for reliable end-to-end testing

Installation

Add to your Cargo.toml:

[dependencies]
playwright-rs = "0.9"  # Auto-updates to latest 0.9.x
tokio = { version = "1", features = ["full"] }

See the CHANGELOG for version history and features.

Browser Installation (Required)

Important: Browsers must be installed separately using the Playwright CLI.

The library bundles Playwright driver version 1.58.2. You must install matching browser versions:

# Install all browsers (recommended)
npx playwright@1.58.2 install

# Or install specific browsers
npx playwright@1.58.2 install chromium firefox webkit

Why version matters: Each Playwright release expects specific browser builds. Using playwright@1.58.2 ensures you get compatible browsers (chromium-1208, firefox-1471, webkit-2248).

In CI/CD: Add this to your GitHub Actions workflow:

- name: Install Playwright Browsers
  run: npx playwright@1.58.2 install chromium firefox webkit --with-deps

The version constant is also available in code:

use playwright_rs::PLAYWRIGHT_VERSION;

println!("Install with: npx playwright@{} install", PLAYWRIGHT_VERSION);

What happens if I don't install browsers? You'll get a helpful error message with the correct install command when trying to launch a browser.

Development

Prerequisites

  • Rust 1.85+
  • Node.js 18+ (for Playwright server and browser installation)
  • tokio async runtime

Building from Source

# Clone repository
git clone https://github.com/YOUR_USERNAME/playwright-rust.git
cd playwright-rust

# Install pre-commit hooks
pip install pre-commit
pre-commit install

# Build
cargo build

Installing Browsers

After building, install browsers as described in Browser Installation above:

cargo build
npx playwright@1.58.2 install chromium firefox webkit

The build script automatically downloads the Playwright driver to drivers/ (gitignored). CI handles browser installation automatically - see .github/workflows/test.yml.

Platform Support: βœ… Windows, macOS, Linux

Running Tests

This project uses cargo-nextest. Install once: cargo install cargo-nextest

cargo nextest run                                    # All tests
cargo nextest run -p playwright-rs --lib             # Unit tests only (~2s, no browsers)
cargo nextest run -p playwright-rs -E 'test(locator)' # Pattern match
cargo test --doc --workspace -- --ignored            # Doc-tests (requires browsers)

Running Examples

See examples/ for usage examples.

cargo run --package playwright-rs --example basic

Star History

Star History Chart

Contributing

This project aims for production-quality Rust bindings matching Playwright's standards. Contributions should:

  • Follow Playwright API conventions
  • Include comprehensive tests
  • Maintain type safety
  • Document public APIs with examples
  • Pass CI checks (fmt, clippy, tests)

License

Apache-2.0 (same as Microsoft Playwright)

Acknowledgments

  • Microsoft Playwright Team - For the amazing browser automation framework
  • playwright-python - API design reference
  • Folio Project - Initial driver for development needs

About

Rust language bindings for Microsoft Playwright

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors