Crate firefox_webdriver

Crate firefox_webdriver 

Source
Expand description

Firefox WebDriver - Undetectable browser automation library.

This library provides a high-level API for automating Firefox browser using a custom WebExtension-based architecture.

§Architecture

The driver follows a client-server model:

  • Local End (Rust): Sends commands, receives events via WebSocket
  • Remote End (Extension): Executes commands in Firefox, emits events

Key design principles:

  • Driver owns a shared ConnectionPool (single WebSocket port)
  • Each Window owns: Firefox process + profile, references shared pool
  • Protocol uses module.methodName format (BiDi-inspired)
  • Elements stored by reference in content script Map (undetectable)
  • Event-driven architecture (no polling)

§Quick Start

use firefox_webdriver::{Driver, Result};

#[tokio::main]
async fn main() -> Result<()> {
    // Build driver with Firefox binary and extension paths
    let driver = Driver::builder()
        .binary("/path/to/firefox")
        .extension("/path/to/extension")
        .build()
        .await?;

    // Spawn a headless browser window
    let window = driver.window().headless().spawn().await?;
    let tab = window.tab();

    // Navigate and interact
    tab.goto("https://example.com").await?;
    let title = tab.get_title().await?;
    println!("Page title: {}", title);

    Ok(())
}

§Modules

ModuleDescription
browserBrowser entities: Window, Tab, Element
driverDriver factory and configuration
errorError types and Result alias
identifiersType-safe ID wrappers
protocolWebSocket message types (internal)
transportWebSocket transport layer (internal)

§Features

  • Undetectable: No navigator.webdriver flag, no detectable globals
  • Event-driven: DOM mutations, network events push to client
  • CSP bypass: Script execution via browser.scripting API
  • Parallel automation: 300+ concurrent windows supported

Re-exports§

pub use browser::BodyAction;
pub use browser::By;
pub use browser::Cookie;
pub use browser::Element;
pub use browser::FrameInfo;
pub use browser::HeadersAction;
pub use browser::ImageFormat;
pub use browser::InterceptedRequest;
pub use browser::InterceptedRequestBody;
pub use browser::InterceptedRequestHeaders;
pub use browser::InterceptedResponse;
pub use browser::InterceptedResponseBody;
pub use browser::Key;
pub use browser::ProxyConfig;
pub use browser::ProxyType;
pub use browser::RequestAction;
pub use browser::RequestBody;
pub use browser::ResponseAction;
pub use browser::ScreenshotBuilder;
pub use browser::Tab;
pub use browser::Window;
pub use driver::Driver;
pub use driver::DriverBuilder;
pub use driver::ExtensionSource;
pub use driver::FirefoxOptions;
pub use driver::Profile;
pub use error::Error;
pub use error::Result;
pub use identifiers::ElementId;
pub use identifiers::FrameId;
pub use identifiers::InterceptId;
pub use identifiers::RequestId;
pub use identifiers::ScriptId;
pub use identifiers::SessionId;
pub use identifiers::SubscriptionId;
pub use identifiers::TabId;

Modules§

browser
Browser entities: Window, Tab, Element.
driver
Driver factory and configuration.
error
Error types and result aliases.
identifiers
Type-safe identifiers for browser entities.
protocol
WebSocket protocol message types.
transport
WebSocket transport layer.