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

Overview

🎭 Playwright for Rust

crates.io docs.rs MIT OR Apache-2.0

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

Installation

[dependencies]
playwright = "0.0.16"

Usage

use playwright::Playwright;

#[tokio::main]
async fn main() -> Result<(), playwright::Error> {
    let playwright = Playwright::initialize().await?;
    playwright.prepare()?; // Install browsers
    let chromium = playwright.chromium();
    let browser = chromium.launcher().headless(true).launch().await?;
    let context = browser.context_builder().build().await?;
    let page = context.new_page().await?;
    page.goto_builder("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(())
}

Async runtimes

These runtimes have passed tests. You can disable tokio, the default feature, and then choose another.

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.

NOTICE

playwright-rust redistributes Playwright licensed under the Apache 2.0.
Playwright has NOTICE:
"""
Playwright
Copyright (c) Microsoft Corporation

This software contains code derived from the Puppeteer project (https://github.com/puppeteer/puppeteer),
available under the Apache 2.0 license (https://github.com/puppeteer/puppeteer/blob/master/LICENSE).
"""

Browser automation in rust

Other languages

Comments
  • Equivalent of `await page.waitForEvent(

    Equivalent of `await page.waitForEvent("load");`

    What's the equivalent of await page.waitForEvent("load"); when using this crate? :) So that I can call it after e.g. page.click_builder("#login-button").click().await?;.

    When I try page.expect_event(EventType::Load).await?; it hangs here forever, even after the page loaded.

    opened by Boscop 13
  • Small changes to make the tests run (Not all tests are passing)

    Small changes to make the tests run (Not all tests are passing)

    Hi, I have made some small changes, to make the tests run. All tests are still not working due to expect_event failing to detect any events correctly OR events are not emitted correctly. Can you shade some light on that?

    opened by tmahmood 6
  • "No such file or directory" error when calling Playwright::initialize()

    I started with this issue of a black browser display, then in an attempt to fix it I set up my dev environment on my new PC (also running Ubuntu 21). Now I'm running into this issue:

    thread 'tokio-runtime-worker' panicked at 'called Result::unwrap() on an Err value: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })', src/bin/webview.rs:39:58

    when I call initialize:

    let playwright = Playwright::initialize().await.unwrap();

    This is the same code that was previously able to launch the browser on my other PC (though it produced a black display, it was operable with javascript and didn't crash).

    Does anyone have an idea of what might be happening here? I'm not specifying a file or directory, but the playwright-rust code apparently is. Though I can't see why it would it be a problem.

    question 
    opened by Randall-Coding 3
  • Can't cross compile to windows

    Can't cross compile to windows

    I'm trying to compile for Windows from Ubuntu 20.x but Playwright seems to be failing during the process.

    I ran the following commands to make it possible to cross compile (or at least that's what a stack overflow article said 😅 ):

    rustup target add x86_64-pc-windows-gnu
    rustup toolchain install stable-x86_64-pc-windows-gnu
    
    cargo build --target x86_64-pc-windows-gnu;
    

    Here is the outputted error:

    rror: couldn't read /home/onx2/Documents/my-project/target/x86_64-pc-windows-gnu/debug/build/playwright-33e13a0aa96f0c95/out\driver.zip: No such file or directory (os error 2)
      --> /home/onx2/.cargo/registry/src/github.com-1ecc6299db9ec823/playwright-0.0.18/src/imp/core/driver.rs:21:32
       |
    21 |     const ZIP: &'static [u8] = include_bytes!(concat!(env!("OUT_DIR"), sep!(), "driver.zip"));
       |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error: couldn't read /home/onx2/Documents/my-project/target/x86_64-pc-windows-gnu/debug/build/playwright-33e13a0aa96f0c95/out\platform: No such file or directory (os error 2)
      --> /home/onx2/.cargo/registry/src/github.com-1ecc6299db9ec823/playwright-0.0.18/src/imp/core/driver.rs:22:36
       |
    22 |     const PLATFORM: &'static str = include_str!(concat!(env!("OUT_DIR"), sep!(), "platform"));
       |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error: could not compile `playwright` due to 2 previous errors
    
    opened by onx2 2
  • Large file upload API implementation and Bug fix

    Large file upload API implementation and Bug fix

    Hello @octaltree,

    Implemented large file upload API, only works for local playwright instance. Also fixed a bug where multiple instances of playwright can not be spawned.

    I have not added tests for these two here. But you can check the tests here: https://github.com/tmahmood/playwright_rs_test

    Regards

    opened by tmahmood 1
  • Write file on element screenshot

    Write file on element screenshot

    This PR implements functionality, which gives an ability to screenshot a specific element. Actually, the logic was copied from the page implementation. Also, i have no idea how to deal with may_save function. so I've made it pub(crate) to use in another module.

    opened by West14 1
  • monitor request and response

    monitor request and response

    Thank you for making a good library. I need response data from the page. This feature is in the rust-headless-chrome, but the overall stability of the library is poor. src_line

    I found this in the playwrite document. Can I use it here, too? network-events

    opened by initprism 1
  • Creating an incognito window

    Creating an incognito window

    Hello,

    is there a way to create an incognito window in playwright-rust?

    I see the comment https://github.com/octaltree/playwright-rust/blob/52c3bbdc00146046ddeec85866737856600f8f5b/src/api/browser_context.rs#L18

    granted, I am not super familiar with playwright and still coming to terms with rustlang.

    opened by afbase 1
  • `ignore_http_errors` should be named `ignore_https_errors` to mirror `ignoreHTTPSErrors`

    `ignore_http_errors` should be named `ignore_https_errors` to mirror `ignoreHTTPSErrors`

    https://github.com/octaltree/playwright-rust/search?q=ignoreHTTPSErrors

    ignore_http_errors should be named ignore_https_errors, (because it's about HTTPS), and mirrors ignoreHTTPSErrors :)

    At first I thought ignoreHTTPSErrors is not supported because I thought ignore_http_errors means something else.

    opened by Boscop 1
  • running in docker env reports some libraries are missing

    running in docker env reports some libraries are missing

    Error "Host system is missing dependencies!\n\n  Missing libraries are:\n      libgobject-2.0.so.0\n      libglib-2.0.so.0\n      libnss3.so\n      libnssutil3.so\n      libsmime3.so\n      libnspr4.so\n      libatk-1.0.so.0\n      libatk-bridge-2.0.so.0\n      libcups.so.2\n      libdrm.so.2\n      libdbus-1.so.3\n      libgio-2.0.so.0\n      libexpat.so.1\n      libxcb.so.1\n      libxkbcommon.so.0\n      libX11.so.6\n      libXcomposite.so.1\n      libXdamage.so.1\n      libXext.so.6\n      libXfixes.so.3\n      libXrandr.so.2\n      libgbm.so.1\n      libpango-1.0.so.0\n      libcairo.so.2\n      libasound.so.2\n      libatspi.so.0\n      libxshmfence.so.1\n"
    
    opened by foragerDev 0
  • None of the browsers are downloading in Playright - Mac M1

    None of the browsers are downloading in Playright - Mac M1

    I get the below error if I use

    let playwright = Playwright::initialize().await.unwrap();
    playwright.prepare();
    

    Error

    Failed to install browsers
    Error: Failed to download chromium, caused by
    Error: ERROR: Playwright does not support chromium on mac13-arm64
    

    Now, even if I select installation of firefox, this same happens

    let playwright = Playwright::initialize().await.unwrap();
    playwright.install_firefox();
    

    Error

    Error: Failed to download firefox, caused by
    Error: ERROR: Playwright does not support firefox on mac13-arm64
    

    I am not willing to have any executable path option, this will be used by some non-tech guy, so I want to keep it simple, like installing the browser and launching automatically.

    My System Config Screenshot 2022-11-12 at 4 08 44 PM

    Can you recommend something here?

    opened by rohitcoder 1
  • Fixed issue with not being able to run playwright tests in parallel, and Implemented set_input_file_paths API

    Fixed issue with not being able to run playwright tests in parallel, and Implemented set_input_file_paths API

    Hi @octaltree,

    This update contains,

    1. Fix for not being able to run multiple instances of playwright,
    2. Implemented set_input_file_paths API

    I have tested the changes in my own test repository, and it works.

    Please review.

    opened by tmahmood 0
  • Startup error with Firefox

    Startup error with Firefox

    I'm not sure of what changed to introduce this issue, and it may just be my own box.

    Firefox started throwing this error on startup: "Gah. Your tab just crashed." The same code was working this last week.

    Error: ErrorResponded(ErrorMessage { name: "Error", message: "Page closed", stack: "Error: Page closed\n    at FFSession.<anonymous> (/home/user/.cache/ms-playwright/playwright-rust/driver/package/lib/server/firefox/ffPage.js:97:31)\n    at Object.onceWrapper (events.js:420:28)\n    at FFSession.emit (events.js:314:20)\n    at /home/user/.cache/ms-playwright/playwright-rust/driver/package/lib/server/firefox/ffConnection.js:175:43" })
    

    playwright-rust: 0.0.20 playwright binary: ms-playwright/firefox-1250 firefox: 89.0b6 os: arch linux

    Chromium appears to work, but sadly is not an option for my use case.

    I've tried deleting the playwright cache and re-downloading but the issue remains.

    When I tried the dev branch it failed with Error: Arc(Serde(Error("missing field `utils`", line: 0, column: 0))).

    question 
    opened by lune-stone 4
  • Playwright dev branch no longer Send (thread safe) after this line of code.

    Playwright dev branch no longer Send (thread safe) after this line of code.

    Conditions: I'm running playwright (dev branch) in two parallel threads like so:

    tokio::spawn(job_x); 
    tokio::spawn(job_y); 
    

    Error: Compilation error occurs saying Playwright is not Send.

    std::marker::Send is not implemented for std::sync::MutexGuard<'_, playwright::"imp"::core::connection::Context> ./src/imp/playwright.rs:76:17

    Diagnosis: I was able to narrow it down to this line of code std::mem::drop(ctx); in imp/playwright.rs

    Partial Solution: After removing that line of code it will compile :+1: . However, though playwright works, it will hang indefinitely after I close the browser window and I have to kill the program manually. I'm not 100% sure it is from removing that line or not yet, but it seems likely.

    1.25 
    opened by Randall-Coding 0
Owner
octaltree
octaltree
Rust Command Line Application for scaffolding Node.js network applications

Thunderstorm.rs ⛈️ Rust Command Line Application for setting up Node.js backend applications. Installation thunderStorm.rs is currently distributed vi

ADEOYE Adefemi 4 Aug 4, 2022
A fuzzer framework built in Rust

lain This crate provides functionality one may find useful while developing a fuzzer. A recent nightly Rust build is required for the specialization f

Microsoft 469 Dec 9, 2022
A snapshotting, coverage-guided fuzzer for software (UEFI, Kernel, firmware, BIOS) built on SIMICS

TSFFS: Target Software Fuzzer For SIMICS TSFFS is a snapshotting, coverage-guided fuzzer built on the SIMICS full system simulator. TSFFS makes it eas

Intel Corporation 194 Oct 9, 2023
Travis CI and AppVeyor template to test your Rust crate on 5 architectures and publish binary releases of it for Linux, macOS and Windows

trust Travis CI and AppVeyor template to test your Rust crate on 5 architectures and publish binary releases of it for Linux, macOS and Windows Featur

Jorge Aparicio 1.2k Dec 30, 2022
Advanced Fuzzing Library - Slot your Fuzzer together in Rust! Scales across cores and machines. For Windows, Android, MacOS, Linux, no_std, ...

LibAFL, the fuzzer library. Advanced Fuzzing Library - Slot your own fuzzers together and extend their features using Rust. LibAFL is written and main

Advanced Fuzzing League ++ 1.2k Dec 29, 2022
A tiny, super simple and portable benchmarking library.

benchmark-simple A tiny benchmarking library for Rust. Trivial to use Works pretty much everywhere, including WebAssembly (WASI, but also in-browser)

Frank Denis 3 Dec 26, 2022
HTTP mocking library for Rust.

httpmock HTTP mocking library for Rust. Documentation · Crate · Report Bug · Request Feature · Changelog Features Simple, expressive, fluent API. Many

Alexander Liesenfeld 320 Dec 21, 2022
A library for generating fake data in Rust.

Fake A Rust library for generating fake data. Installation Default (rand is required): [dependencies] fake = "2.4" rand = "0.8" If you want to use #[d

cksac 552 Dec 25, 2022
QuickCheck bug hunting in Rust standard library data structures

BugHunt, Rust This project is aiming to provide "stateful" QuickCheck models for Rust's standard library. That is, we build up a random list of operat

Brian L. Troutwine 161 Dec 15, 2022
Rust testing library

K9 - Rust Testing Library Snapshot testing + better assertions Available test macros snapshot assert_equal assert_greater_than assert_greater_than_or_

Aaron Abramov 269 Dec 10, 2022
Struct mocking library for Rust

faux   A library to create mocks out of structs. faux allows you to mock the methods of structs for testing without complicating or polluting your cod

Andres 322 Dec 20, 2022
beaver is a library for setting up Rust objects inspired by factory_bot.

beaver is a library for setting up Rust objects inspired by factory_bot. Usage | Examples | Docs Dependencies [dependenci

Takayuki Maeda 40 Sep 6, 2022
Rustress - stress testing library in Rust. For fun

rustress Simple network stress testing library. To get familiar with Rust Planned features (Subject to change) Multithreaded client/server Throughput

Hakan Sönmez 7 Sep 22, 2022
insta: a snapshot testing library for Rust

insta: a snapshot testing library for Rust Introduction Snapshots tests (also sometimes called approval tests) are tests that assert values against a

Armin Ronacher 1.4k Jan 1, 2023
Simple assertion library for unit testing in python with a fluent API

Simple assertions library for unit testing in Python with a nice fluent API. Supports both Python 2 and 3.

snakedye 19 Sep 10, 2022
This is a tiny (but delightful!) utility library for exhaustive testing.

Exhaustigen This is a tiny (but delightful!) utility library for exhaustive testing. It is based (directly) on the idea and code in the following blog

Graydon Hoare 34 Dec 14, 2022
A minimalist property-based testing library based on the arbitrary crate.

A minimalist property-based testing library based on the arbitrary crate.

Aleksey Kladov 61 Dec 21, 2022
A structure-aware HTTP fuzzing library

?? FeroxFuzz ?? A structure-aware HTTP fuzzing library ?? Another ferox? why? ?? Chill, it's not another command-line tool, this one's a library! ?? M

epi 141 Dec 27, 2022
An unofficial client library for the fuzz-introspector API.

fuzz-introspector-client An unofficial client library for the fuzz-introspector API. Quickstart Add package as a dependency; cargo add fuzz-introspect

Nathaniel Brough 4 Nov 25, 2023