Skip to main content
Nodriver provides comprehensive methods for managing browser cookies and storage. This is essential for maintaining sessions, testing authentication flows, and handling state.

Working with cookies

The browser object provides a cookies property for cookie management:

Getting all cookies

Retrieve all cookies from the browser:
From browser.py:734-769:

Getting cookies in requests format

Get cookies compatible with the Python requests library:
This is useful when you need to transfer cookies from a browser session to API calls made with requests.

Setting cookies

Set cookies programmatically:

Clearing cookies

Remove all cookies from the browser:
From browser.py:880-898:
Clearing cookies affects all tabs and windows in the browser instance.

Saving and loading cookies

Save cookies to file

Persist cookies for later use:
From browser.py:791-834:

Load cookies from file

Restore previously saved cookies:
For more control, use the Chrome DevTools Protocol directly:

Working with localStorage

Access browser localStorage using JavaScript evaluation:

Working with sessionStorage

Similar to localStorage but scoped to the tab:

IndexedDB access

For IndexedDB operations, use JavaScript:

Cache storage

Manage cache storage via CDP:

Real-world example: Login persistence

Here’s a complete example of maintaining login state:

Working with service workers

Manage service workers using CDP:

Best practices