Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NODRIVER] [BUG] Exception on headless mode #2120

Open
FRIKIdelTO opened this issue Jan 20, 2025 · 3 comments
Open

[NODRIVER] [BUG] Exception on headless mode #2120

FRIKIdelTO opened this issue Jan 20, 2025 · 3 comments

Comments

@FRIKIdelTO
Copy link

FRIKIdelTO commented Jan 20, 2025

System:
Chrome 132.0.6834.84 (Build oficial) (64 bits)
Windows 11 64bit (tested too on Windows 10 64bit)

test code:

import asyncio
import nodriver as uc

async def test_nodriver(url):
    browser = await uc.Browser.create(headless=True)
    tab = await browser.get(url)
    await tab
    html = await tab.get_content()
    browser.stop()
    return html

html = uc.loop().run_until_complete(test_nodriver('https://example.com'))
print(html)

traceback:

Traceback (most recent call last):
  File "D:\PYTHON\test_nodriver.py", line 12, in <module>
    html = uc.loop().run_until_complete(test_nodriver('https://example.com'))
  File "C:\python\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "D:\PYTHON\test_nodriver.py", line 5, in test_nodriver
    browser = await uc.Browser.create(headless=True)
  File "C:\python\lib\site-packages\nodriver\core\browser.py", line 90, in create
    await instance.start()
  File "C:\python\lib\site-packages\nodriver\core\browser.py", line 393, in start
    await self.connection.send(cdp.target.set_discover_targets(discover=True))
  File "C:\python\lib\site-packages\nodriver\core\connection.py", line 413, in send
    await self._prepare_headless()
  File "C:\python\lib\site-packages\nodriver\core\connection.py", line 492, in _prepare_headless
    response, error = await self._send_oneshot(
TypeError: cannot unpack non-iterable NoneType object
@stephanlensky
Copy link

Hi @FRIKIdelTO, I created a fork of nodriver here stephanlensky/zendriver which fixes this and other bugs, feel free to take a look.

@khamaileon
Copy link

I can confirm that the problem is resolved with Zendriver.

@mdmintz
Copy link

mdmintz commented Jan 29, 2025

Until the maintainer of nodriver returns, I have a working fix in https://github.com/seleniumbase/SeleniumBase.
(The CDP Mode inside there includes a nodriver fork with fixes and improvements.)

Here's the updated script:

import asyncio
from seleniumbase.undetected import cdp_driver

async def main():
    browser = await cdp_driver.cdp_util.start_async(headless=True)
    tab = await browser.get("https://example.com")
    await tab
    html = await tab.get_content()
    browser.stop()
    return html

if __name__ == "__main__":
    loop = asyncio.new_event_loop()
    html = loop.run_until_complete(main())
    print(html)

There's also a sync format if you don't like using async/await.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants