parthtamu/rag-code-assistant
0
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4 <head>5 <meta charset="utf-8" />6 <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="webbrowser — Convenient web-browser controller" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/webbrowser.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Source code: Lib/webbrowser.py The webbrowser module provides a high-level interface to allow displaying web-based documents to users. Under most circumstances, simply calling the open() function f..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_webbrowser_bf42c23d.png" />15<meta property="og:image:alt" content="Source code: Lib/webbrowser.py The webbrowser module provides a high-level interface to allow displaying web-based documents to users. Under most circumstances, simply calling the open() function f..." />16<meta name="description" content="Source code: Lib/webbrowser.py The webbrowser module provides a high-level interface to allow displaying web-based documents to users. Under most circumstances, simply calling the open() function f..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20 <title>webbrowser — Convenient web-browser controller — Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21 22 <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23 <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24 <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25 <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26 <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27 28 <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29 <script src="../_static/doctools.js?v=9bcbadda"></script>30 <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31 <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32 33 <script src="../_static/sidebar.js"></script>34 35 <link rel="search" type="application/opensearchdescription+xml"36 title="Search within Python 3.15.0a6 documentation"37 href="../_static/opensearch.xml"/>38 <link rel="author" title="About these documents" href="../about.html" />39 <link rel="index" title="Index" href="../genindex.html" />40 <link rel="search" title="Search" href="../search.html" />41 <link rel="copyright" title="Copyright" href="../copyright.html" />42 <link rel="next" title="wsgiref — WSGI Utilities and Reference Implementation" href="wsgiref.html" />43 <link rel="prev" title="Internet Protocols and Support" href="internet.html" />44 45 46 <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47 48 <link rel="canonical" href="https://docs.python.org/3/library/webbrowser.html">49 50 51 52 53 <style>54 @media only screen {55 table.full-width-table {56 width: 100%;57 }58 }59 </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61 <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62 <script type="text/javascript" src="../_static/copybutton.js"></script>63 <script type="text/javascript" src="../_static/menu.js"></script>64 <script type="text/javascript" src="../_static/search-focus.js"></script>65 <script type="text/javascript" src="../_static/themetoggle.js"></script> 66 <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67 <meta name="readthedocs-addons-api-version" content="1">68 69 </head>70<body>71<div class="mobile-nav">72 <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73 aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74 <nav class="nav-content" role="navigation">75 <label for="menuToggler" class="toggler__label">76 <span></span>77 </label>78 <span class="nav-items-wrapper">79 <a href="https://www.python.org/" class="nav-logo">80 <img src="../_static/py.svg" alt="Python logo">81 </a>82 <span class="version_switcher_placeholder"></span>83 <form role="search" class="search" action="../search.html" method="get">84 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85 <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>86 </svg>87 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88 <input type="submit" value="Go">89 </form>90 </span>91 </nav>92 <div class="menu-wrapper">93 <nav class="menu" role="navigation" aria-label="main navigation">94 <div class="language_switcher_placeholder"></div>95 96<label class="theme-selector-label">97 Theme98 <select class="theme-selector" oninput="activateTheme(this.value)">99 <option value="auto" selected>Auto</option>100 <option value="light">Light</option>101 <option value="dark">Dark</option>102 </select>103</label>104 <div>105 <h3><a href="../contents.html">Table of Contents</a></h3>106 <ul>107<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">webbrowser</span></code> — Convenient web-browser controller</a><ul>108<li><a class="reference internal" href="#command-line-interface">Command-line interface</a></li>109<li><a class="reference internal" href="#browser-controller-objects">Browser controller objects</a></li>110</ul>111</li>112</ul>113 114 </div>115 <div>116 <h4>Previous topic</h4>117 <p class="topless"><a href="internet.html"118 title="previous chapter">Internet Protocols and Support</a></p>119 </div>120 <div>121 <h4>Next topic</h4>122 <p class="topless"><a href="wsgiref.html"123 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref</span></code> — WSGI Utilities and Reference Implementation</a></p>124 </div>125 <script>126 document.addEventListener('DOMContentLoaded', () => {127 const title = document.querySelector('meta[property="og:title"]').content;128 const elements = document.querySelectorAll('.improvepage');129 const pageurl = window.location.href.split('?')[0];130 elements.forEach(element => {131 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));132 url.searchParams.set('pagetitle', title);133 url.searchParams.set('pageurl', pageurl);134 url.searchParams.set('pagesource', "library/webbrowser.rst");135 element.href = url.toString();136 });137 });138 </script>139 <div role="note" aria-label="source link">140 <h3>This page</h3>141 <ul class="this-page-menu">142 <li><a href="../bugs.html">Report a bug</a></li>143 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>144 <li>145 <a href="https://github.com/python/cpython/blob/main/Doc/library/webbrowser.rst?plain=1"146 rel="nofollow">Show source147 </a>148 </li>149 150 </ul>151 </div>152 </nav>153 </div>154</div>155 156 157 <div class="related" role="navigation" aria-label="Related">158 <h3>Navigation</h3>159 <ul>160 <li class="right" style="margin-right: 10px">161 <a href="../genindex.html" title="General Index"162 accesskey="I">index</a></li>163 <li class="right" >164 <a href="../py-modindex.html" title="Python Module Index"165 >modules</a> |</li>166 <li class="right" >167 <a href="wsgiref.html" title="wsgiref — WSGI Utilities and Reference Implementation"168 accesskey="N">next</a> |</li>169 <li class="right" >170 <a href="internet.html" title="Internet Protocols and Support"171 accesskey="P">previous</a> |</li>172 173 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>174 <li><a href="https://www.python.org/">Python</a> »</li>175 <li class="switchers">176 <div class="language_switcher_placeholder"></div>177 <div class="version_switcher_placeholder"></div>178 </li>179 <li>180 181 </li>182 <li id="cpython-language-and-version">183 <a href="../index.html">3.15.0a6 Documentation</a> »184 </li>185 186 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>187 <li class="nav-item nav-item-2"><a href="internet.html" accesskey="U">Internet Protocols and Support</a> »</li>188 <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">webbrowser</span></code> — Convenient web-browser controller</a></li>189 <li class="right">190 191 192 <div class="inline-search" role="search">193 <form class="inline-search" action="../search.html" method="get">194 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">195 <input type="submit" value="Go">196 </form>197 </div>198 |199 </li>200 <li class="right">201<label class="theme-selector-label">202 Theme203 <select class="theme-selector" oninput="activateTheme(this.value)">204 <option value="auto" selected>Auto</option>205 <option value="light">Light</option>206 <option value="dark">Dark</option>207 </select>208</label> |</li>209 210 </ul>211 </div> 212 213 <div class="document">214 <div class="documentwrapper">215 <div class="bodywrapper">216 <div class="body" role="main">217 218 <section id="module-webbrowser">219<span id="webbrowser-convenient-web-browser-controller"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">webbrowser</span></code> — Convenient web-browser controller<a class="headerlink" href="#module-webbrowser" title="Link to this heading">¶</a></h1>220<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/webbrowser.py">Lib/webbrowser.py</a></p>221<hr class="docutils" />222<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">webbrowser</span></code> module provides a high-level interface to allow displaying223web-based documents to users. Under most circumstances, simply calling the224<a class="reference internal" href="#webbrowser.open" title="webbrowser.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> function from this module will do the right thing.</p>225<p>Under Unix, graphical browsers are preferred under X11, but text-mode browsers226will be used if graphical browsers are not available or an X11 display isn’t227available. If text-mode browsers are used, the calling process will block until228the user exits the browser.</p>229<p>If the environment variable <span class="target" id="index-0"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">BROWSER</span></code> exists, it is interpreted as the230<a class="reference internal" href="os.html#os.pathsep" title="os.pathsep"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.pathsep</span></code></a>-separated list of browsers to try ahead of the platform231defaults. When the value of a list part contains the string <code class="docutils literal notranslate"><span class="pre">%s</span></code>, then it is232interpreted as a literal browser command line to be used with the argument URL233substituted for <code class="docutils literal notranslate"><span class="pre">%s</span></code>; if the value is a single word that refers to one of the234already registered browsers this browser is added to the front of the search list;235if the part does not contain <code class="docutils literal notranslate"><span class="pre">%s</span></code>, it is simply interpreted as the name of the236browser to launch. <a class="footnote-reference brackets" href="#id2" id="id1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a></p>237<div class="versionchanged">238<p><span class="versionmodified changed">Changed in version 3.14: </span>The <span class="target" id="index-1"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">BROWSER</span></code> variable can now also be used to reorder the list of239platform defaults. This is particularly useful on macOS where the platform240defaults do not refer to command-line tools on <span class="target" id="index-2"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code>.</p>241</div>242<p>For non-Unix platforms, or when a remote browser is available on Unix, the243controlling process will not wait for the user to finish with the browser, but244allow the remote browser to maintain its own windows on the display. If remote245browsers are not available on Unix, the controlling process will launch a new246browser and wait.</p>247<p>On iOS, the <span class="target" id="index-3"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">BROWSER</span></code> environment variable, as well as any arguments248controlling autoraise, browser preference, and new tab/window creation will be249ignored. Web pages will <em>always</em> be opened in the user’s preferred browser, in250a new tab, with the browser being brought to the foreground. The use of the251<code class="xref py py-mod docutils literal notranslate"><span class="pre">webbrowser</span></code> module on iOS requires the <a class="reference internal" href="ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a> module. If252<code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code> isn’t available, calls to <a class="reference internal" href="#webbrowser.open" title="webbrowser.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> will fail.</p>253<section id="command-line-interface">254<span id="webbrowser-cli"></span><h2>Command-line interface<a class="headerlink" href="#command-line-interface" title="Link to this heading">¶</a></h2>255<p>The script <strong class="program">webbrowser</strong> can be used as a command-line interface for the256module. It accepts a URL as the argument. It accepts the following optional257parameters:</p>258<dl class="std option">259<dt class="sig sig-object std" id="cmdoption-webbrowser-n">260<span id="cmdoption-webbrowser-new-window"></span><span class="sig-name descname"><span class="pre">-n</span></span><span class="sig-prename descclassname"></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">--new-window</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-webbrowser-n" title="Link to this definition">¶</a></dt>261<dd><p>Opens the URL in a new browser window, if possible.</p>262</dd></dl>263 264<dl class="std option">265<dt class="sig sig-object std" id="cmdoption-webbrowser-t">266<span id="cmdoption-webbrowser-new-tab"></span><span class="sig-name descname"><span class="pre">-t</span></span><span class="sig-prename descclassname"></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">--new-tab</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-webbrowser-t" title="Link to this definition">¶</a></dt>267<dd><p>Opens the URL in a new browser tab.</p>268</dd></dl>269 270<p>The options are, naturally, mutually exclusive. Usage example:</p>271<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>python<span class="w"> </span>-m<span class="w"> </span>webbrowser<span class="w"> </span>-t<span class="w"> </span><span class="s2">"https://www.python.org"</span>272</pre></div>273</div>274<div class="availability docutils container">275<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: not WASI, not Android.</p>276</div>277<p>The following exception is defined:</p>278<dl class="py exception">279<dt class="sig sig-object py" id="webbrowser.Error">280<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">webbrowser.</span></span><span class="sig-name descname"><span class="pre">Error</span></span><a class="headerlink" href="#webbrowser.Error" title="Link to this definition">¶</a></dt>281<dd><p>Exception raised when a browser control error occurs.</p>282</dd></dl>283 284<p>The following functions are defined:</p>285<dl class="py function">286<dt class="sig sig-object py" id="webbrowser.open">287<span class="sig-prename descclassname"><span class="pre">webbrowser.</span></span><span class="sig-name descname"><span class="pre">open</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">new</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">autoraise</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#webbrowser.open" title="Link to this definition">¶</a></dt>288<dd><p>Display <em>url</em> using the default browser. If <em>new</em> is 0, the <em>url</em> is opened289in the same browser window if possible. If <em>new</em> is 1, a new browser window290is opened if possible. If <em>new</em> is 2, a new browser page (“tab”) is opened291if possible. If <em>autoraise</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the window is raised if possible292(note that under many window managers this will occur regardless of the293setting of this variable).</p>294<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if a browser was successfully launched, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</p>295<p>Note that on some platforms, trying to open a filename using this function,296may work and start the operating system’s associated program. However, this297is neither supported nor portable.</p>298<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">webbrowser.open</span></code> with argument <code class="docutils literal notranslate"><span class="pre">url</span></code>.</p>299</dd></dl>300 301<dl class="py function">302<dt class="sig sig-object py" id="webbrowser.open_new">303<span class="sig-prename descclassname"><span class="pre">webbrowser.</span></span><span class="sig-name descname"><span class="pre">open_new</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#webbrowser.open_new" title="Link to this definition">¶</a></dt>304<dd><p>Open <em>url</em> in a new window of the default browser, if possible, otherwise, open305<em>url</em> in the only browser window.</p>306<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if a browser was successfully launched, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</p>307</dd></dl>308 309<dl class="py function">310<dt class="sig sig-object py" id="webbrowser.open_new_tab">311<span class="sig-prename descclassname"><span class="pre">webbrowser.</span></span><span class="sig-name descname"><span class="pre">open_new_tab</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#webbrowser.open_new_tab" title="Link to this definition">¶</a></dt>312<dd><p>Open <em>url</em> in a new page (“tab”) of the default browser, if possible, otherwise313equivalent to <a class="reference internal" href="#webbrowser.open_new" title="webbrowser.open_new"><code class="xref py py-func docutils literal notranslate"><span class="pre">open_new()</span></code></a>.</p>314<p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if a browser was successfully launched, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</p>315</dd></dl>316 317<dl class="py function">318<dt class="sig sig-object py" id="webbrowser.get">319<span class="sig-prename descclassname"><span class="pre">webbrowser.</span></span><span class="sig-name descname"><span class="pre">get</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">using</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#webbrowser.get" title="Link to this definition">¶</a></dt>320<dd><p>Return a controller object for the browser type <em>using</em>. If <em>using</em> is321<code class="docutils literal notranslate"><span class="pre">None</span></code>, return a controller for a default browser appropriate to the322caller’s environment.</p>323</dd></dl>324 325<dl class="py function">326<dt class="sig sig-object py" id="webbrowser.register">327<span class="sig-prename descclassname"><span class="pre">webbrowser.</span></span><span class="sig-name descname"><span class="pre">register</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">constructor</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">instance</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">preferred</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#webbrowser.register" title="Link to this definition">¶</a></dt>328<dd><p>Register the browser type <em>name</em>. Once a browser type is registered, the329<a class="reference internal" href="#webbrowser.get" title="webbrowser.get"><code class="xref py py-func docutils literal notranslate"><span class="pre">get()</span></code></a> function can return a controller for that browser type. If330<em>instance</em> is not provided, or is <code class="docutils literal notranslate"><span class="pre">None</span></code>, <em>constructor</em> will be called without331parameters to create an instance when needed. If <em>instance</em> is provided,332<em>constructor</em> will never be called, and may be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>333<p>Setting <em>preferred</em> to <code class="docutils literal notranslate"><span class="pre">True</span></code> makes this browser a preferred result for334a <a class="reference internal" href="#webbrowser.get" title="webbrowser.get"><code class="xref py py-func docutils literal notranslate"><span class="pre">get()</span></code></a> call with no argument. Otherwise, this entry point is only335useful if you plan to either set the <span class="target" id="index-4"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">BROWSER</span></code> variable or call336<code class="xref py py-func docutils literal notranslate"><span class="pre">get()</span></code> with a nonempty argument matching the name of a handler you337declare.</p>338<div class="versionchanged">339<p><span class="versionmodified changed">Changed in version 3.7: </span><em>preferred</em> keyword-only parameter was added.</p>340</div>341</dd></dl>342 343<p>A number of browser types are predefined. This table gives the type names that344may be passed to the <a class="reference internal" href="#webbrowser.get" title="webbrowser.get"><code class="xref py py-func docutils literal notranslate"><span class="pre">get()</span></code></a> function and the corresponding instantiations345for the controller classes, all defined in this module.</p>346<table class="docutils align-default">347<thead>348<tr class="row-odd"><th class="head"><p>Type Name</p></th>349<th class="head"><p>Class Name</p></th>350<th class="head"><p>Notes</p></th>351</tr>352</thead>353<tbody>354<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'mozilla'</span></code></p></td>355<td><p><code class="docutils literal notranslate"><span class="pre">Mozilla('mozilla')</span></code></p></td>356<td></td>357</tr>358<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'firefox'</span></code></p></td>359<td><p><code class="docutils literal notranslate"><span class="pre">Mozilla('mozilla')</span></code></p></td>360<td></td>361</tr>362<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'epiphany'</span></code></p></td>363<td><p><code class="docutils literal notranslate"><span class="pre">Epiphany('epiphany')</span></code></p></td>364<td></td>365</tr>366<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'kfmclient'</span></code></p></td>367<td><p><code class="docutils literal notranslate"><span class="pre">Konqueror()</span></code></p></td>368<td><p>(1)</p></td>369</tr>370<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'konqueror'</span></code></p></td>371<td><p><code class="docutils literal notranslate"><span class="pre">Konqueror()</span></code></p></td>372<td><p>(1)</p></td>373</tr>374<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'kfm'</span></code></p></td>375<td><p><code class="docutils literal notranslate"><span class="pre">Konqueror()</span></code></p></td>376<td><p>(1)</p></td>377</tr>378<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'opera'</span></code></p></td>379<td><p><code class="docutils literal notranslate"><span class="pre">Opera()</span></code></p></td>380<td></td>381</tr>382<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'links'</span></code></p></td>383<td><p><code class="docutils literal notranslate"><span class="pre">GenericBrowser('links')</span></code></p></td>384<td></td>385</tr>386<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'elinks'</span></code></p></td>387<td><p><code class="docutils literal notranslate"><span class="pre">Elinks('elinks')</span></code></p></td>388<td></td>389</tr>390<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'lynx'</span></code></p></td>391<td><p><code class="docutils literal notranslate"><span class="pre">GenericBrowser('lynx')</span></code></p></td>392<td></td>393</tr>394<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'w3m'</span></code></p></td>395<td><p><code class="docutils literal notranslate"><span class="pre">GenericBrowser('w3m')</span></code></p></td>396<td></td>397</tr>398<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'windows-default'</span></code></p></td>399<td><p><code class="docutils literal notranslate"><span class="pre">WindowsDefault</span></code></p></td>400<td><p>(2)</p></td>401</tr>402<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'macosx'</span></code></p></td>403<td><p><code class="docutils literal notranslate"><span class="pre">MacOSXOSAScript('default')</span></code></p></td>404<td><p>(3)</p></td>405</tr>406<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'safari'</span></code></p></td>407<td><p><code class="docutils literal notranslate"><span class="pre">MacOSXOSAScript('safari')</span></code></p></td>408<td><p>(3)</p></td>409</tr>410<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'google-chrome'</span></code></p></td>411<td><p><code class="docutils literal notranslate"><span class="pre">Chrome('google-chrome')</span></code></p></td>412<td></td>413</tr>414<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'chrome'</span></code></p></td>415<td><p><code class="docutils literal notranslate"><span class="pre">Chrome('chrome')</span></code></p></td>416<td></td>417</tr>418<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'chromium'</span></code></p></td>419<td><p><code class="docutils literal notranslate"><span class="pre">Chromium('chromium')</span></code></p></td>420<td></td>421</tr>422<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'chromium-browser'</span></code></p></td>423<td><p><code class="docutils literal notranslate"><span class="pre">Chromium('chromium-browser')</span></code></p></td>424<td></td>425</tr>426<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'iosbrowser'</span></code></p></td>427<td><p><code class="docutils literal notranslate"><span class="pre">IOSBrowser</span></code></p></td>428<td><p>(4)</p></td>429</tr>430</tbody>431</table>432<p>Notes:</p>433<ol class="arabic simple">434<li><p>“Konqueror” is the file manager for the KDE desktop environment for Unix, and435only makes sense to use if KDE is running. Some way of reliably detecting KDE436would be nice; the <code class="xref std std-envvar docutils literal notranslate"><span class="pre">KDEDIR</span></code> variable is not sufficient. Note also that437the name “kfm” is used even when using the <strong class="program">konqueror</strong> command with KDE4382 — the implementation selects the best strategy for running Konqueror.</p></li>439<li><p>Only on Windows platforms.</p></li>440<li><p>Only on macOS.</p></li>441<li><p>Only on iOS.</p></li>442</ol>443<div class="versionadded">444<p><span class="versionmodified added">Added in version 3.2: </span>A new <code class="xref py py-class docutils literal notranslate"><span class="pre">MacOSXOSAScript</span></code> class has been added445and is used on Mac instead of the previous <code class="xref py py-class docutils literal notranslate"><span class="pre">MacOSX</span></code> class.446This adds support for opening browsers not currently set as the OS default.</p>447</div>448<div class="versionadded">449<p><span class="versionmodified added">Added in version 3.3: </span>Support for Chrome/Chromium has been added.</p>450</div>451<div class="versionchanged">452<p><span class="versionmodified changed">Changed in version 3.12: </span>Support for several obsolete browsers has been removed.453Removed browsers include Grail, Mosaic, Netscape, Galeon,454Skipstone, Iceape, and Firefox versions 35 and below.</p>455</div>456<div class="versionchanged">457<p><span class="versionmodified changed">Changed in version 3.13: </span>Support for iOS has been added.</p>458</div>459<p>Here are some simple examples:</p>460<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">url</span> <span class="o">=</span> <span class="s1">'https://docs.python.org/'</span>461 462<span class="c1"># Open URL in a new tab, if a browser window is already open.</span>463<span class="n">webbrowser</span><span class="o">.</span><span class="n">open_new_tab</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>464 465<span class="c1"># Open URL in new window, raising the window if possible.</span>466<span class="n">webbrowser</span><span class="o">.</span><span class="n">open_new</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>467</pre></div>468</div>469</section>470<section id="browser-controller-objects">471<span id="browser-controllers"></span><h2>Browser controller objects<a class="headerlink" href="#browser-controller-objects" title="Link to this heading">¶</a></h2>472<p>Browser controllers provide the <a class="reference internal" href="#webbrowser.controller.name" title="webbrowser.controller.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> attribute,473and the following three methods which parallel module-level convenience functions:</p>474<dl class="py attribute">475<dt class="sig sig-object py" id="webbrowser.controller.name">476<span class="sig-prename descclassname"><span class="pre">controller.</span></span><span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#webbrowser.controller.name" title="Link to this definition">¶</a></dt>477<dd><p>System-dependent name for the browser.</p>478</dd></dl>479 480<dl class="py method">481<dt class="sig sig-object py" id="webbrowser.controller.open">482<span class="sig-prename descclassname"><span class="pre">controller.</span></span><span class="sig-name descname"><span class="pre">open</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">new</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">autoraise</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#webbrowser.controller.open" title="Link to this definition">¶</a></dt>483<dd><p>Display <em>url</em> using the browser handled by this controller. If <em>new</em> is 1, a new484browser window is opened if possible. If <em>new</em> is 2, a new browser page (“tab”)485is opened if possible.</p>486</dd></dl>487 488<dl class="py method">489<dt class="sig sig-object py" id="webbrowser.controller.open_new">490<span class="sig-prename descclassname"><span class="pre">controller.</span></span><span class="sig-name descname"><span class="pre">open_new</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#webbrowser.controller.open_new" title="Link to this definition">¶</a></dt>491<dd><p>Open <em>url</em> in a new window of the browser handled by this controller, if492possible, otherwise, open <em>url</em> in the only browser window. Alias493<a class="reference internal" href="#webbrowser.open_new" title="webbrowser.open_new"><code class="xref py py-func docutils literal notranslate"><span class="pre">open_new()</span></code></a>.</p>494</dd></dl>495 496<dl class="py method">497<dt class="sig sig-object py" id="webbrowser.controller.open_new_tab">498<span class="sig-prename descclassname"><span class="pre">controller.</span></span><span class="sig-name descname"><span class="pre">open_new_tab</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#webbrowser.controller.open_new_tab" title="Link to this definition">¶</a></dt>499<dd><p>Open <em>url</em> in a new page (“tab”) of the browser handled by this controller, if500possible, otherwise equivalent to <a class="reference internal" href="#webbrowser.open_new" title="webbrowser.open_new"><code class="xref py py-func docutils literal notranslate"><span class="pre">open_new()</span></code></a>.</p>501</dd></dl>502 503<p class="rubric">Footnotes</p>504<aside class="footnote-list brackets">505<aside class="footnote brackets" id="id2" role="doc-footnote">506<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id1">1</a><span class="fn-bracket">]</span></span>507<p>Executables named here without a full path will be searched in the508directories given in the <span class="target" id="index-5"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> environment variable.</p>509</aside>510</aside>511</section>512</section>513 514 515 <div class="clearer"></div>516 </div>517 </div>518 </div>519 <div class="sphinxsidebar" role="navigation" aria-label="Main">520 <div class="sphinxsidebarwrapper">521 <div>522 <h3><a href="../contents.html">Table of Contents</a></h3>523 <ul>524<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">webbrowser</span></code> — Convenient web-browser controller</a><ul>525<li><a class="reference internal" href="#command-line-interface">Command-line interface</a></li>526<li><a class="reference internal" href="#browser-controller-objects">Browser controller objects</a></li>527</ul>528</li>529</ul>530 531 </div>532 <div>533 <h4>Previous topic</h4>534 <p class="topless"><a href="internet.html"535 title="previous chapter">Internet Protocols and Support</a></p>536 </div>537 <div>538 <h4>Next topic</h4>539 <p class="topless"><a href="wsgiref.html"540 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref</span></code> — WSGI Utilities and Reference Implementation</a></p>541 </div>542 <script>543 document.addEventListener('DOMContentLoaded', () => {544 const title = document.querySelector('meta[property="og:title"]').content;545 const elements = document.querySelectorAll('.improvepage');546 const pageurl = window.location.href.split('?')[0];547 elements.forEach(element => {548 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));549 url.searchParams.set('pagetitle', title);550 url.searchParams.set('pageurl', pageurl);551 url.searchParams.set('pagesource', "library/webbrowser.rst");552 element.href = url.toString();553 });554 });555 </script>556 <div role="note" aria-label="source link">557 <h3>This page</h3>558 <ul class="this-page-menu">559 <li><a href="../bugs.html">Report a bug</a></li>560 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>561 <li>562 <a href="https://github.com/python/cpython/blob/main/Doc/library/webbrowser.rst?plain=1"563 rel="nofollow">Show source564 </a>565 </li>566 567 </ul>568 </div>569 </div>570<div id="sidebarbutton" title="Collapse sidebar">571<span>«</span>572</div>573 574 </div>575 <div class="clearer"></div>576 </div> 577 <div class="related" role="navigation" aria-label="Related">578 <h3>Navigation</h3>579 <ul>580 <li class="right" style="margin-right: 10px">581 <a href="../genindex.html" title="General Index"582 >index</a></li>583 <li class="right" >584 <a href="../py-modindex.html" title="Python Module Index"585 >modules</a> |</li>586 <li class="right" >587 <a href="wsgiref.html" title="wsgiref — WSGI Utilities and Reference Implementation"588 >next</a> |</li>589 <li class="right" >590 <a href="internet.html" title="Internet Protocols and Support"591 >previous</a> |</li>592 593 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>594 <li><a href="https://www.python.org/">Python</a> »</li>595 <li class="switchers">596 <div class="language_switcher_placeholder"></div>597 <div class="version_switcher_placeholder"></div>598 </li>599 <li>600 601 </li>602 <li id="cpython-language-and-version">603 <a href="../index.html">3.15.0a6 Documentation</a> »604 </li>605 606 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>607 <li class="nav-item nav-item-2"><a href="internet.html" >Internet Protocols and Support</a> »</li>608 <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">webbrowser</span></code> — Convenient web-browser controller</a></li>609 <li class="right">610 611 612 <div class="inline-search" role="search">613 <form class="inline-search" action="../search.html" method="get">614 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">615 <input type="submit" value="Go">616 </form>617 </div>618 |619 </li>620 <li class="right">621<label class="theme-selector-label">622 Theme623 <select class="theme-selector" oninput="activateTheme(this.value)">624 <option value="auto" selected>Auto</option>625 <option value="light">Light</option>626 <option value="dark">Dark</option>627 </select>628</label> |</li>629 630 </ul>631 </div> 632 <div class="footer">633 © <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.634 <br>635 This page is licensed under the Python Software Foundation License Version 2.636 <br>637 Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.638 <br>639 640 See <a href="/license.html">History and License</a> for more information.<br>641 642 643 <br>644 645 The Python Software Foundation is a non-profit corporation.646<a href="https://www.python.org/psf/donations/">Please donate.</a>647<br>648 <br>649 Last updated on Mar 10, 2026 (08:58 UTC).650 651 <a href="/bugs.html">Found a bug</a>?652 653 <br>654 655 Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.656 </div>657 658 </body>659</html>