Browser class is the root of the Zendriver hierarchy and represents the browser process. You typically create one Browser instance per automation session.
Creating a browser instance
You create browser instances using the asynchronousBrowser.create() method, not the constructor:
Configuration options
Thecreate() method accepts various configuration parameters:
Common parameters
Run browser in headless mode (no UI)
Directory for browser profile data. Auto-generates temporary directory if not specified
Path to browser executable. Auto-detects if not specified
Browser type:
"chrome", "brave", or "auto"Enable browser sandbox. Automatically disabled when running as root
Custom user agent string
Navigating to URLs
Use theget() method to navigate to URLs:
browser.py
get() method:
- Waits for DOM events to fire
- Handles navigation timing automatically
- Returns a
Tabobject for further interaction
Working with tabs
Access browser tabs through properties:tabs.py
Tab properties
Returns the first tab launched with the browser
Returns all current tabs (targets of type “page”)
Returns all targets including iframes, service workers, and background scripts
Managing browser lifecycle
Starting the browser
The browser starts automatically when you callcreate(), but you can also start it manually:
Stopping the browser
Always stop the browser when done to clean up resources:Waiting
Use thewait() or sleep() methods to pause execution:
Managing cookies
Access cookies through thecookies property:
cookies.py
Granting permissions
Grant all browser permissions at once:- Audio/video capture
- Geolocation
- Notifications
- Clipboard access
- And many more
Window management
Tile multiple browser windows:Advanced usage
Connecting to existing browser
Connect to a running browser instance:Using custom configuration
Create aConfig object for advanced settings:
Target discovery
Automatically discover new tabs and windows:Browser properties
WebSocket debugger URL for the browser connection
The active browser-level connection object
Browser configuration object
Whether the browser process has stopped
Best practices
Always stop the browser
Always stop the browser
Chromium processes can be stubborn. Always call
await browser.stop() or use context managers to ensure proper cleanup.Reuse browser instances
Reuse browser instances
Creating browser instances is expensive. Reuse the same browser and open multiple tabs instead of creating new browsers.
Use unique user data directories
Use unique user data directories
If running multiple browsers simultaneously, provide unique
user_data_dir values to avoid conflicts.Wait between navigations
Wait between navigations
Error handling
Next steps
Tabs
Learn how to work with browser tabs
Elements
Interact with page elements
Configuration
Advanced configuration options