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

'NoneType' object has no attribute 'closed' - Chrome 129 - Browser opens but program crashes #12

Closed
ahmb opened this issue Nov 10, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@ahmb
Copy link

ahmb commented Nov 10, 2024

Any assistance on this would be much appreciated !

Get this error with Chrome 130 , the browser opens but doesnt navigate to any website and the terminal has the error output

using python 3.10 + macOS

example being used:

import zendriver as uc
import asyncio

async def main():

    browser = await uc.start()
    page = await browser.get('https://www.webfunnel.ca')
    await browser.close()

if __name__ == '__main__':
    # since asyncio.run never worked (for me)
    asyncio.run(main())

also tried using browser = await uc.start(browser_args=['--headless=new'])

(base) ➜  nodriver /opt/homebrew/opt/[email protected]/bin/python3.10 example1.py
Traceback (most recent call last):
  File "/Users/Newton/Documents/code/webScraping/nodriver/example1.py", line 12, in <module>
    asyncio.run(main())
  File "/opt/homebrew/Cellar/[email protected]/3.10.15/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/opt/homebrew/Cellar/[email protected]/3.10.15/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/Users/Newton/Documents/code/webScraping/nodriver/example1.py", line 6, in main
    browser = await uc.start()
  File "/opt/homebrew/lib/python3.10/site-packages/zendriver/core/util.py", line 95, in start
    return await Browser.create(config)
  File "/opt/homebrew/lib/python3.10/site-packages/zendriver/core/browser.py", line 91, in create
    await instance.start()
  File "/opt/homebrew/lib/python3.10/site-packages/zendriver/core/browser.py", line 394, in start
    await self.connection.send(cdp.target.set_discover_targets(discover=True))
  File "/opt/homebrew/lib/python3.10/site-packages/zendriver/core/connection.py", line 414, in send
    if not self.websocket or self.closed:
  File "/opt/homebrew/lib/python3.10/site-packages/zendriver/core/connection.py", line 370, in __getattr__
    return getattr(self.target, item)
AttributeError: 'NoneType' object has no attribute 'closed'
/opt/homebrew/lib/python3.10/site-packages/zendriver/core/util.py:145: RuntimeWarning: coroutine 'Browser.stop' was never awaited
  _.stop()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
@drjgouveia
Copy link

I'm currently having the exact same issue :(

@therealpurplemana
Copy link

I am seeing this on Windows machines now. My Macintosh and Ubuntu Chrome seems okay.

@drjgouveia
Copy link

@therealpurplemana it happened to me in Ubuntu

@stephanlensky
Copy link
Owner

This is due to a breaking change in websockets==14.0. Thanks @rhjsong @therealpurplemana for the tip. Related nodriver issues:

So, the solution is to keep using websockets==13.1 until we can fix the incompatibility.

I just released a new version of zendriver, 0.1.2 which pins websockets<14. If you upgrade to the latest zendriver, it should automatically downgrade your version of websockets and solve the problem.

If not, you can also try

pip install websockets==13.1

To force the downgrade.

@stephanlensky stephanlensky self-assigned this Nov 12, 2024
@stephanlensky stephanlensky added the bug Something isn't working label Nov 12, 2024
@stephanlensky
Copy link
Owner

stephanlensky commented Nov 12, 2024

I created a new issue #14 for supporting the latest websockets version, but since pinning the older version fixes the crash I'll close this issue for now.

@stephanlensky
Copy link
Owner

stephanlensky commented Nov 12, 2024

Unrelated, but this made me realize my example code

import zendriver as uc
import asyncio

async def main():

    browser = await uc.start()
    page = await browser.get('https://www.webfunnel.ca')
    await browser.close()

if __name__ == '__main__':
    # since asyncio.run never worked (for me)
    asyncio.run(main())

is wrong, it should be

await browser.stop()

sorry about that! I just went back and fixed it in all of the docs and examples.

@stephanlensky stephanlensky pinned this issue Nov 12, 2024
@ahmb
Copy link
Author

ahmb commented Nov 13, 2024

awesome ! thanks so much for the note. I upgraded to the latest zendriver and that fixed my issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants