38 lines
8.6 KiB
HTML
38 lines
8.6 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Rust library to open URLs and local files in the web browsers available on a platform, with guarantees of Consistent Behaviour."><title>webbrowser - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="webbrowser" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../webbrowser/index.html">webbrowser</a><span class="version">1.0.3</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li><li><a href="#platform-support-status" title="Platform Support Status">Platform Support Status</a></li><li><a href="#consistent-behaviour" title="Consistent Behaviour">Consistent Behaviour</a></li><li><a href="#crate-features" title="Crate Features">Crate Features</a></li></ul><h3><a href="#structs">Crate Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>webbrowser</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/webbrowser/lib.rs.html#1-443">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Rust library to open URLs and local files in the web browsers available on a platform, with guarantees of <a href="#consistent-behaviour">Consistent Behaviour</a>.</p>
|
||
<p>Inspired by the <a href="https://docs.python.org/2/library/webbrowser.html">webbrowser</a> python library.</p>
|
||
<h3 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h3>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>webbrowser;
|
||
|
||
<span class="kw">if </span>webbrowser::open(<span class="string">"http://github.com"</span>).is_ok() {
|
||
<span class="comment">// ...
|
||
</span>}</code></pre></div>
|
||
<h3 id="platform-support-status"><a class="doc-anchor" href="#platform-support-status">§</a>Platform Support Status</h3><div><table><thead><tr><th>Platform</th><th>Supported</th><th>Browsers</th><th>Test status</th></tr></thead><tbody>
|
||
<tr><td>macOS</td><td>✅</td><td>default + <a href="https://docs.rs/webbrowser/latest/webbrowser/enum.Browser.html">others</a></td><td>✅</td></tr>
|
||
<tr><td>windows</td><td>✅</td><td>default only</td><td>✅</td></tr>
|
||
<tr><td>linux/wsl</td><td>✅</td><td>default only (respects $BROWSER env var, so can be used with other browsers)</td><td>✅</td></tr>
|
||
<tr><td>android</td><td>✅</td><td>default only</td><td>✅</td></tr>
|
||
<tr><td>iOS/tvOS/visionOS</td><td>✅</td><td>default only</td><td>✅</td></tr>
|
||
<tr><td>wasm</td><td>✅</td><td>default only</td><td>✅</td></tr>
|
||
<tr><td>unix (*bsd, aix etc.)</td><td>✅</td><td>default only (respects $BROWSER env var, so can be used with other browsers)</td><td>Manual</td></tr>
|
||
</tbody></table>
|
||
</div><h3 id="consistent-behaviour"><a class="doc-anchor" href="#consistent-behaviour">§</a>Consistent Behaviour</h3>
|
||
<p><code>webbrowser</code> defines consistent behaviour on all platforms as follows:</p>
|
||
<ul>
|
||
<li><strong>Browser guarantee</strong> - 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.</li>
|
||
<li><strong>Non-Blocking</strong> for GUI based browsers (e.g. Firefox, Chrome etc.), while <strong>Blocking</strong> for text based browser (e.g. lynx etc.)</li>
|
||
<li><strong>Suppressed output</strong> by default for GUI based browsers, so that their stdout/stderr don’t pollute the main program’s output. This can be
|
||
overridden by <code>webbrowser::open_browser_with_options</code>.</li>
|
||
</ul>
|
||
<h3 id="crate-features"><a class="doc-anchor" href="#crate-features">§</a>Crate Features</h3>
|
||
<p><code>webbrowser</code> optionally allows the following features to be configured:</p>
|
||
<ul>
|
||
<li><code>hardened</code> - this disables handling of non-http(s) urls (e.g. <code>file:///</code>) as a hard security precaution</li>
|
||
<li><code>disable-wsl</code> - this disables WSL <code>file</code> implementation (<code>http</code> still works)</li>
|
||
<li><code>wasm-console</code> - this enables logging to wasm console (valid only on wasm platform)</li>
|
||
</ul>
|
||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.BrowserOptions.html" title="struct webbrowser::BrowserOptions">Browser<wbr>Options</a></div><div class="desc docblock-short">BrowserOptions to override certain default behaviour. Any option named as a <code>hint</code> is
|
||
not guaranteed to be honoured. Use <a href="struct.BrowserOptions.html#method.new" title="associated function webbrowser::BrowserOptions::new">BrowserOptions::new()</a> to create.</div></li><li><div class="item-name"><a class="struct" href="struct.ParseBrowserError.html" title="struct webbrowser::ParseBrowserError">Parse<wbr>Browser<wbr>Error</a></div><div class="desc docblock-short">The Error type for parsing a string into a Browser.</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.Browser.html" title="enum webbrowser::Browser">Browser</a></div><div class="desc docblock-short">Browser types available</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.open.html" title="fn webbrowser::open">open</a></div><div class="desc docblock-short">Opens the URL on the default browser of this platform</div></li><li><div class="item-name"><a class="fn" href="fn.open_browser.html" title="fn webbrowser::open_browser">open_<wbr>browser</a></div><div class="desc docblock-short">Opens the specified URL on the specific browser (if available) requested. Return semantics are
|
||
the same as for <a href="fn.open.html">open</a>.</div></li><li><div class="item-name"><a class="fn" href="fn.open_browser_with_options.html" title="fn webbrowser::open_browser_with_options">open_<wbr>browser_<wbr>with_<wbr>options</a></div><div class="desc docblock-short">Opens the specified URL on the specific browser (if available) requested, while overriding the
|
||
default options.</div></li></ul></section></div></main></body></html> |