Skip to main content
The Browser object is the root of the nodriver hierarchy and represents the browser process. It manages tabs, browser contexts, and the connection to the Chrome DevTools Protocol.

Creating a browser instance

You create browser instances using the asynchronous Browser.create() method, not through direct instantiation:
The Browser object must be created using await Browser.create() rather than Browser(). Direct instantiation will raise a RuntimeError.

Configuration options

The create() method accepts several configuration parameters:
Config
default:"None"
A Config object with browser settings. If not provided, a default configuration is created.
PathLike
default:"None"
Directory for browser profile data. If not specified, a temporary directory is created.
bool
default:"False"
Run the browser in headless mode without a visible window.
PathLike
default:"None"
Path to the Chrome/Chromium executable. Auto-detected if not provided.
List[str]
default:"None"
Additional command-line arguments to pass to the browser.
bool
default:"True"
Enable or disable the browser sandbox. Automatically disabled when running as root.
str
default:"None"
Host address for the DevTools Protocol connection. Defaults to “127.0.0.1”.
int
default:"None"
Port for the DevTools Protocol connection. Auto-assigned if not provided.

Example with configuration

Key properties

Main tab

Access the primary tab that was launched with the browser:

All tabs

Get a list of all open tabs (targets of type “page”):

Cookies

Access the browser’s cookie jar for managing cookies across all tabs:
Use the get() method to navigate in the current tab or open new tabs/windows:

Accessing tabs

You can access tabs by index or search:

Browser contexts

Create isolated browser contexts, useful for different proxy configurations:
str
default:"'chrome://welcome'"
URL to open in the new context.
bool
default:"True"
Open in a new window instead of a tab.
str
default:"None"
Proxy server to use. Supports HTTP, HTTPS, and SOCKS5 with authentication. Format: http://username:password@server:port or socks://username:password@server:port
bool
default:"True"
Automatically dispose the context when the debugging session disconnects.
Chrome typically only supports one proxy per browser instance. Use create_context() with different proxy settings to work around this limitation.

Permissions

Grant all browser permissions at once:
This grants permissions for:
  • Audio and video capture
  • Clipboard access
  • Geolocation
  • Notifications
  • Sensors
  • And many more

Window management

Tile windows

Arrange multiple browser windows in a grid layout:

Lifecycle management

Waiting and sleeping

Allow the browser to update its state:

Stopping the browser

Terminate the browser process:
The browser automatically attempts to clean up on exit, but calling stop() explicitly ensures proper shutdown.

Using context manager

For automatic cleanup, use the BrowserContext context manager:
bool
default:"False"
Set to True to prevent automatic browser closure when exiting the context.

Iteration

Iterate through all tabs:

Connection details

Access the WebSocket debugger URL:
Check if the browser is still running:

Best practices

Most browser operations are asynchronous. Always use await when calling browser methods.
Store tab objects when you need to interact with specific tabs later. The browser maintains a list of all targets, but keeping your own references makes code clearer.
Always ensure the browser is properly closed using stop() or a context manager to avoid orphaned browser processes.
You can connect to an already-running Chrome instance by specifying both host and port parameters when creating the browser.