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 asynchronousBrowser.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
Thecreate() method accepts several configuration parameters:
A Config object with browser settings. If not provided, a default configuration is created.
Directory for browser profile data. If not specified, a temporary directory is created.
Run the browser in headless mode without a visible window.
Path to the Chrome/Chromium executable. Auto-detected if not provided.
Additional command-line arguments to pass to the browser.
Enable or disable the browser sandbox. Automatically disabled when running as root.
Host address for the DevTools Protocol connection. Defaults to “127.0.0.1”.
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:Navigation and tab management
Navigate to a URL
Use theget() 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:URL to open in the new context.
Open in a new window instead of a tab.
Proxy server to use. Supports HTTP, HTTPS, and SOCKS5 with authentication.
Format:
http://username:password@server:port or socks://username:password@server:portAutomatically dispose the context when the debugging session disconnects.
Permissions
Grant all browser permissions at once:- 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 theBrowserContext context manager:
Set to
True to prevent automatic browser closure when exiting the context.Iteration
Iterate through all tabs:Connection details
Access the WebSocket debugger URL:Best practices
Use await for browser operations
Use await for browser operations
Most browser operations are asynchronous. Always use
await when calling browser methods.Keep references to tabs
Keep references to tabs
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.
Handle browser cleanup
Handle browser cleanup
Always ensure the browser is properly closed using
stop() or a context manager to avoid orphaned browser processes.Connect to existing browsers
Connect to existing browsers
You can connect to an already-running Chrome instance by specifying both
host and port parameters when creating the browser.Related documentation
- Tab management - Learn about controlling individual tabs
- Configuration - Detailed configuration options
- Element interaction - Working with page elements