webbrowser

Open URLs and local files in the platform's web browser from Rust, with guaranteed consistent behaviour on every OS.

Library
Cargo
v1.2.4
328stars
Apache-2.0 OR MIT

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
66/100Good
Development Activity72
Maintenance52
Community60
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
87/100Excellent
Architecture88
Code Quality82
Innovation90
Learning Curve95

webbrowser is a small, dependency-light Rust crate that opens URLs and local files in whatever web browser is available on the current platform. Inspired by Python’s webbrowser module, it exposes a single open() call that works across macOS, Windows, Linux/WSL, Android, iOS, and WebAssembly.

Unlike approaches that shell out to a generic system “open” command, webbrowser guarantees that a browser is actually launched — even for local HTML files — rather than an editor or some other default handler. It is non-blocking for GUI browsers, blocking for text browsers, and suppresses browser stdout/stderr by default so it never pollutes your program’s output.

What You Get

  • A single webbrowser::open(url) entry point that works identically across every supported platform.
  • Guaranteed browser launch for both remote URLs and local files, avoiding the wrong-app problem of generic open commands.
  • Fine-grained control via open_browser_with_options and a builder-style BrowserOptions (output suppression, target hints, dry-run, macOS window focus).
  • Broad platform coverage: macOS, Windows, Linux/WSL, other Unixes, Android, iOS/tvOS/visionOS, and WebAssembly.
  • Optional hardening features (hardened, disable-wsl) for security-sensitive contexts.

Common Use Cases

  • Opening OAuth or login flows in the user’s browser from a CLI or desktop app.
  • Launching generated reports, docs, or local HTML previews from a build or dev tool.
  • Pointing users to release notes, dashboards, or help pages directly from an application.

Under The Hood

Architecture - src/lib.rs defines the public surface (open, open_browser, open_browser_with_options, the Browser enum, and the BrowserOptions builder) and uses #[cfg_attr(..., path = ...)] to bind a single private os module to exactly one platform backend: macos.rs, windows.rs, unix.rs, android.rs, ios.rs, or wasm.rs. Every public call normalizes the input into a TargetType and dispatches to os::open_browser_internal, so callers get one API while each OS handles launch its own way.

Tech Stack - Pure Rust (edition 2021, MSRV 1.85) with a deliberately tiny dependency set: log for diagnostics and url for parsing. Platform backends pull targeted deps only where needed — objc2/objc2-foundation/objc2-app-kit for macOS and iOS, jni/ndk-context for Android, and web-sys (Window) for WASM — all gated behind cfg(target_os = ...). Dev-dependencies (actix-web, tokio, serial_test) exist only to spin up local servers for the integration tests.

Code Quality - Shared process-launch logic lives in src/common.rs (run_command handling background spawn vs. foreground status, output suppression, and dry-run), keeping the per-OS files focused. The crate ships per-platform integration test suites (tests/test_macos.rs, test_windows.rs, test_unix.rs, test_wasm.rs, etc.) plus dedicated Android/iOS/WASM test apps, exercised across six CI workflows. Error handling uses std::io::Result with descriptive ErrorKinds rather than panicking.

API Design - The API is about as small as it gets: webbrowser::open("https://...") returns a Result and is the whole happy path. Advanced needs use a fluent BrowserOptions::new().with_suppress_output(false) builder passed to open_browser_with_options, and Browser::exists() gives a dry-run availability probe. Naming is consistent and self-documenting, and near-zero boilerplate is required to get started.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search