I'm trying to debug an error occurring with nodriver when I attempt to start a browser session. The code used to work but now raises an error after updating to a new setup. Here is a simplified script to reproduce the issue:
import nodriver as ucimport timeimport logginglogging.basicConfig(level=logging.DEBUG)async def test_nodriver(): agent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" try: browser = await uc.start(headless=True, browser_args=[f"--user-agent={agent}"]) logging.info("Browser started successfully") page = await browser.get("https://www.nowsecure.nl") time.sleep(1) await browser.start.save_screenshot("image.png") logging.info("Screenshot saved successfully") except Exception as e: logging.error(f"Failed to start browser: {e}")if __name__ == "__main__": uc.loop().run_until_complete(test_nodriver())Error Traceback
After running this script, I get the following error traceback:
Traceback (most recent call last): File "/home/me/project/src/test_nodriver.py", line 22, in <module> uc.loop().run_until_complete(test_nodriver()) File "/usr/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/home/me/project/src/test_nodriver.py", line 10, in test_nodriver browser = await uc.start(headless=True, browser_args=[f"--user-agent={agent}"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/me/project/.venv/lib/python3.12/site-packages/nodriver/core/util.py", line 96, in start return await Browser.create(config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/me/project/.venv/lib/python3.12/site-packages/nodriver/core/browser.py", line 91, in create await instance.start() File "/home/me/project/.venv/lib/python3.12/site-packages/nodriver/core/browser.py", line 394, in start await self.connection.send(cdp.target.set_discover_targets(discover=True)) File "/home/me/project/.venv/lib/python3.12/site-packages/nodriver/core/connection.py", line 420, in send await self._prepare_headless() File "/home/me/project/.venv/lib/python3.12/site-packages/nodriver/core/connection.py", line 499, in _prepare_headless response, error = await self._send_oneshot( ^^^^^^^^^^^^^^^TypeError: cannot unpack non-iterable NoneType objectEnvironment Information
- OS: Linux Ubuntu 24.04.1 LTS
- Python: 3.12.6
- nodriver: 0.37
- Chromium: 130.0.6723.69 (installed via Snap)
Description of the Issue
From the debug logs, it appears nodriver is failing to initialize the browser connection. I suspect it could be an issue with the version compatibility between nodriver and Chromium or with how nodriver is handling WebSocket communication in headless mode.
Has anyone encountered a similar issue with recent versions of Python, nodriver, or Chromium? Is there a workaround or a configuration tweak that can resolve the NoneType error during the browser startup process?