Registry / http-networking / browser-cookie3

browser-cookie3

JSON →
library0.20.1pypypi✓ verified 21d ago

browser-cookie3 is a Python library that loads cookies from various web browsers (Chrome, Firefox, Edge, Safari, Opera, Brave, etc.) into a `cookiejar` object. This enables Python programs, often used for web scraping or automation, to download content as seen in a web browser without needing to re-authenticate. The library is actively maintained, with frequent updates to support new browser versions and address changes in cookie storage mechanisms.

pip install browser-cookie3
INSTALL
IMPORT
SIG · BROWSER-COOKIE3
B
browser-cookie3
http-networkingpythonv0.20.1
Install
2.3s avg
Import
176ms
Disk
32MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.20.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.3s · import 0.176s · 34MB
32MB installed
● package 32MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

browser_cookie3
import browser_cookie3
The library is imported as `browser_cookie3`.
chrome
cj = browser_cookie3.chrome()
cj = browser_cookie.chrome()
Ensure you are using `browser_cookie3` (Python 3 fork) and not the older `browser_cookie` module, which was for Python 2.

This quickstart demonstrates how to load cookies from a specific browser (e.g., Chrome) and then use them with the popular `requests` library to access a website as if you were logged in. The `domain_name` argument is optional but recommended for performance and security. Replace 'example.com' with the target domain.

import browser_cookie3 import requests import os def get_cookies_for_requests(browser_function): """Gets cookies from a specified browser function and returns a requests.cookies.RequestsCookieJar.""" try: # The specific browser function (e.g., browser_cookie3.chrome()) # returns a http.cookiejar.CookieJar object. cj = browser_function(domain_name='example.com') # Filter for a specific domain for efficiency return cj except Exception as e: print(f"Error loading cookies from {browser_function.__name__}: {e}") return None # Example: Get cookies from Chrome and use them with requests # Make sure you are logged into 'example.com' in Chrome before running. chrome_cookies = get_cookies_for_requests(browser_cookie3.chrome) if chrome_cookies: print(f"Successfully loaded {len(list(chrome_cookies))} cookies from Chrome.") # Use the cookies with the requests library # Replace 'https://example.com' with the actual URL you want to access # Ensure the URL matches the domain for which cookies were loaded. try: response = requests.get('https://example.com', cookies=chrome_cookies) response.raise_for_status() # Raise an HTTPError for bad responses (4xx or 5xx) print(f"Successfully fetched page from example.com. Status code: {response.status_code}") # print(response.text[:500]) # Print first 500 characters of the content except requests.exceptions.RequestException as e: print(f"Request failed: {e}") else: print("Could not load cookies from Chrome. Make sure Chrome is running and you are logged in.") # You can also try other browsers: # firefox_cookies = get_cookies_for_requests(browser_cookie3.firefox) # if firefox_cookies: # print(f"Loaded {len(list(firefox_cookies))} cookies from Firefox.")
Debug
Known issues
gotchaBrowser updates frequently change cookie storage formats, encryption methods, or file locations. These external changes can unexpectedly break `browser-cookie3`'s ability to locate or decrypt cookies for specific browser versions or operating systems. Users may need to wait for library updates to restore compatibility.
fix
Check the GitHub repository's issues for reported compatibility problems and potential workarounds. Update `browser-cookie3` to the latest version. Consider using `cj = browser_cookie3.load()` to try all supported browsers if one fails.
affects: All versions, due to external dependencies.
breakingMajor browsers (Chrome, Firefox, Safari) are phasing out or severely restricting third-party cookies. While `browser-cookie3` primarily handles first-party cookies, this broader change in the web's cookie landscape might affect expected scraping behavior or introduce new errors if your target websites rely on third-party cookie functionality for authentication or content delivery.
fix
Adapt web scraping strategies to rely less on third-party cookies. Be aware that sites may implement new anti-bot or privacy measures that impact automated access even with first-party cookies.
affects: All versions. This is an ecosystem-level change.
gotchaUsers frequently report browser-specific and OS-specific issues, such as cookie decryption failures for Microsoft Edge or Chrome on certain Windows versions, incorrect Firefox profile detection on Linux, or the library ceasing to function entirely on particular setups. These often manifest as `FileNotFoundError`, decryption errors, or empty cookie jars.
fix
Provide detailed environment information (OS, browser, browser version, Python version) when reporting issues on GitHub. Test with different browsers or on different operating systems if possible. Ensure your browser profile is not locked or inaccessible.
affects: All versions, depends on user environment.
gotchaOn Linux, `dbus-python` and `jeepney` are crucial dependencies for `browser-cookie3` to interact with some browsers. Users often encounter errors if these packages are not correctly installed, especially `dbus-python`, which may require system-level packages (e.g., `python3-dbus` on Debian/Ubuntu) in addition to pip installation.
fix
Ensure `dbus-python` and `jeepney` are installed. On Debian/Ubuntu, try `sudo apt-get install python3-dbus` in addition to `pip install browser-cookie3`.
affects: All versions on Linux.
breakingA segmentation fault (`Segfault`) has been reported when running `browser-cookie3` with Python 3.14 (specifically, in a free-threaded build). This indicates a potential incompatibility with future Python versions, which might break functionality for users upgrading their Python environment.
fix
If encountering segfaults with Python 3.14+, consider using an earlier Python version (e.g., 3.11, 3.12, 3.13) or a non-free-threaded build. Monitor the GitHub repository for updates addressing this compatibility issue.
affects: Potentially Python 3.14 and later (free-threaded builds).
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'browser_cookie3'
The 'browser-cookie3' package is either not installed, or the Python interpreter running the script cannot find it in its `sys.path`.
fix
Ensure the package is correctly installed in your active Python environment: `pip install browser-cookie3` or `pip3 install browser-cookie3`.
browser_cookie3.BrowserCookieError: Unable to get key for cookie decryption
This error typically occurs when Chrome's cookie encryption method has changed, making it difficult for `browser-cookie3` to decrypt the stored cookies, especially on Windows due to changes like App-Bound Encryption in Chrome versions 127 and above.
fix
Update `browser-cookie3` to its latest version (`pip install --upgrade browser-cookie3`), as new versions often include fixes for updated browser encryption. If the issue persists, consider alternative methods for cookie extraction, such as using Selenium. On macOS, ensuring your terminal/IDE has 'Full Disk Access' might also resolve related decryption issues.
browser_cookie3.BrowserCookieError: Failed to find Chrome cookie
The library could not locate the browser's cookie database file, which can happen if the browser's cookie file path has changed (e.g., Chrome 96+ moved its cookie file location), the browser is currently running and locking the file, or a specific domain has no cookies.
fix
Close all instances of the browser before running the script. Update `browser-cookie3` to the latest version (`pip install --upgrade browser-cookie3`). If issues persist, you might need to manually specify the `cookie_file` path, especially if using non-default browser profiles (e.g., `cj = browser_cookie3.chrome(cookie_file='/path/to/your/Cookies')`).
PermissionError: [Errno 1] Operation not permitted: '/Users/<my_user_name>/Library/Containers/com.apple.Safari/Data/Library/Cookies/Cookies.binarycookies'
On macOS, the Python script lacks the necessary file system permissions to access the browser's cookie database, often due to macOS's stricter privacy and security settings.
fix
Grant 'Full Disk Access' to the terminal application (e.g., Terminal, iTerm) or the IDE (e.g., VS Code, PyCharm) that is executing the Python script. This setting can be found in macOS System Settings > Privacy & Security > Full Disk Access.
Upgrade
Version history
0.20.1latest on PyPI · released Jan 4, 2025
Audit
Dependencies
lz4requiredRequired for certain cookie decryption operations.
pycryptodomexrequiredRequired for decrypting encrypted browser cookies.
dbus-pythonrequiredRequired on Linux for D-Bus communication with some browsers to retrieve cookie information.
jeepneyrequiredPure Python D-Bus interface, often used in conjunction with dbus-python.
shadowcopyrequiredLikely used for accessing locked cookie databases.
Agent activity
69 hits · last 30 days
node
62
OpenAI (training)
1
Resources
browser-cookie3 — pip install browser-cookie3 · libregistry