nodriver crashes with infinite recursion in headless mode when running browser.get()

Here is the code I'm trying to run:
import nodriver as uc
async def main():
browser = await uc.start(headless=True)
page = await browser.get('https://www.nowsecure.nl')
if __name__ == '__main__':
uc.loop().run_until_complete(main())
Here is the output I get in the terminal:
File ".venv/lib/python3.12/site-packages/nodriver/core/tab.py", line 217, in _prepare_headless
resp = await self._send_oneshot(
^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.12/site-packages/nodriver/core/connection.py", line 522, in _send_oneshot
return await self.send(cdp_obj, _is_update=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.12/site-packages/nodriver/core/tab.py", line 208, in send
await self._prepare_headless()
File ".venv/lib/python3.12/site-packages/nodriver/core/tab.py", line 217, in _prepare_headless
resp = await self._send_oneshot(
^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.12/site-packages/nodriver/core/connection.py", line 522, in _send_oneshot
return await self.send(cdp_obj, _is_update=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded
successfully removed temp profile /tmp/uc_8kjtj4bv
I'm not sure whether this is a bug, or whether I'm doing something wrong (e.g., something is wrong with my environment). In case it was a bug, I tried raising an issue on the repository's github page (https://github.com/ultrafunkamsterdam/nodriver/issues/new), but I keep getting a "Unable to create issue" error. I experimented with another repo and this error did not come up, so I'm assuming the repository owner has turned off issues or something...?
Answer
you're encountering a RecursionError
due to an infinite recursive call between _prepare_headless()
and send()
in nodriver
, which seems to be triggered only in headless mode.
In the current version of nodriver
, there's a circular call where:
send()
calls_prepare_headless()
_prepare_headless()
callssend()
again
→ This loop causes infinite recursion and eventually aRecursionError
.
This is likely a bug in nodriver
's headless support.
If you run without headless mode (just to confirm that it's headless-related), you would see that it works:
import nodriver as uc
from time import sleep
async def main():
browser = await uc.start(headless=False)
page = await browser.get('https://www.nowsecure.nl')
if __name__ == '__main__':
uc.loop().run_until_complete(main())
sleep(2)