36 releases (4 stable)

1.0.3 Nov 28, 2024
1.0.1 May 6, 2024
0.8.15 Apr 10, 2024
0.8.13 Mar 5, 2024
0.1.2 Dec 8, 2015

#8 in Web programming

Download history 68120/week @ 2024-08-22 66921/week @ 2024-08-29 70073/week @ 2024-09-05 62811/week @ 2024-09-12 63038/week @ 2024-09-19 68067/week @ 2024-09-26 69301/week @ 2024-10-03 71998/week @ 2024-10-10 76305/week @ 2024-10-17 82181/week @ 2024-10-24 88540/week @ 2024-10-31 83725/week @ 2024-11-07 82910/week @ 2024-11-14 88515/week @ 2024-11-21 98024/week @ 2024-11-28 81103/week @ 2024-12-05

364,975 downloads per month
Used in 750 crates (258 directly)

MIT/Apache

77KB
1.5K SLoC

webbrowser

Current Crates.io Version Crates.io Downloads License

Linux Build Windows Build MacOS Build iOS Build Android Build WASM Build

Rust library to open URLs and local files in the web browsers available on a platform, with guarantees of Consistent Behaviour.

Inspired by the webbrowser python library

Documentation

Examples

use webbrowser;

if webbrowser::open("http://github.com").is_ok() {
    // ...
}

Platform Support

Platform Supported Browsers Test status
macos default + others
windows default only
linux/wsl default only (respects $BROWSER env var, so can be used with other browsers)
android default only
ios/tvOS/visionOS default only
wasm default only
unix (*bsd, aix etc.) default only (respects $BROWSER env var, so can be used with other browsers) Manual

Consistent Behaviour

webbrowser defines consistent behaviour on all platforms as follows:

  • Browser guarantee - This library guarantees that the browser is opened, even for local files - the only crate to make such guarantees at the time of this writing. Alternative libraries rely on existing system commands, which may lead to an editor being opened (instead of the browser) for local html files, leading to an inconsistent behaviour for users.
  • Non-Blocking for GUI based browsers (e.g. Firefox, Chrome etc.), while Blocking for text based browser (e.g. lynx etc.)
  • Suppressed output by default for GUI based browsers, so that their stdout/stderr don't pollute the main program's output. This can be overridden by webbrowser::open_browser_with_options.

Crate Features

webbrowser optionally allows the following features to be configured:

  • hardened - this disables handling of non-http(s) urls (e.g. file:///) as a hard security precaution
  • disable-wsl - this disables WSL file implementation (http still works)
  • wasm-console - this enables logging to wasm console (valid only on wasm platform)

Looking to contribute?

PRs invited for

  • Bugs
  • Supporting non-default browser invocation on any platform

Important note (while testing):

  • This library requires availability of browsers and a graphical environment during runtime
  • cargo test will actually open the browser locally

When contributing, please note that your work will be dual licensed as MIT + Apache-2.0 (see below).

License

SPDX-License-Identifier: Apache-2.0 OR MIT

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2–13MB
~155K SLoC