11.1 webbrowser -- Convenient Web-browser controller
Keywords: lib

# 11.1 `webbrowser` -- Convenient Web-browser controller

The `webbrowser` module provides a very high-level interface to allow displaying Web-based documents to users. The controller objects are easy to use and are platform independent.

Under Unix, graphical browsers are preferred under X11, but text-mode browsers will be used if graphical browsers are not available or an X11 display isn't available. If text-mode browsers are used, the calling process will block until the user exits the browser.

For non-Unix platforms, or when X11 browsers are available on Unix, the controlling process will not wait for the user to finish with the browser, but allow the browser to maintain its own window on the display.

The following exception is defined:

`Error`
  Exception raised when a browser control error occurs.

The following functions are defined:

`open` (url[, new])
  Display url using the default browser. If new is true, a new browser window is opened if possible.

`open_new` (url)
  Open url in a new window of the default browser, if possible, otherwise, open url in the only browser window.

`get` ([name])
  Return a controller object for the browser type name.

`register` (name, constructor[, controller])
  Register the browser type name. Once a browser type is registered, the `get()` function can return a controller for that browser type. If instance is not provided, or is `None`, constructor will be called without parameters to create an instance when needed. If instance is provided, constructor will never be called, and may be `None`.

Several browser types are defined. This table gives the type names that may be passed to the `get()` function and the names of the implementation classes, all defined in this module.

Type Name | Class Name | Notes
--- | --- | ---
`'netscape'` | `Netscape` |
`'kfm'` | `Konquerer` | (1)
`'grail'` | `Grail` |
`'windows-default'` | `WindowsDefault` | (2)
`'internet-config'` | `InternetConfig` | (3)
`'command-line'` | `CommandLineBrowser` |

Notes:

(1)
  ``Konquerer'' is the file manager for the KDE desktop environment for UNIX, and only makes sense to use if KDE is running. Some way of reliably detecting KDE would be nice; the $KDEDIR variable is not sufficient.

(2)
  Only on Windows platforms; requires the common extension modules `win32api` and `win32con`.

(3)
  Only on MacOS platforms; requires the standard MacPython `ic` module, described in the Macintosh Library Modules manual.

Subsections

- 11.1.1 Browser Controller Objects