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

Unable to run in headless=False mode due to pyppeteer.errors.NetworkError: Protocol error Page.getFrameTree: Target closed. #435

Open
BhavyaLight opened this issue Apr 18, 2023 · 3 comments

Comments

@BhavyaLight
Copy link

import asyncio
from pyppeteer import launch

async def main():
    browser = await launch(headless=False)
    page = await browser.newPage()
    
asyncio.get_event_loop().run_until_complete(main())

pyppeteer version 1.0.2

pyppeteer.errors.NetworkError: Protocol error Page.getFrameTree: Target closed.
connection unexpectedly closed
Task exception was never retrieved
future: <Task finished name='Task-22' coro=<Connection._async_send() done, defined at /Users/peurrr/Desktop/sample/env/lib/python3.9/site-packages/pyppeteer/connection.py:69> exception=InvalidStateError('invalid state')>
Traceback (most recent call last):
  File "/Users/peurrr/Desktop/sample/env/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 968, in transfer_data
    message = await self.read_message()
  File "/Users/peurrr/Desktop/sample/env/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 1038, in read_message
    frame = await self.read_data_frame(max_size=self.max_size)
  File "/Users/peurrr/Desktop/sample/env/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 1113, in read_data_frame
    frame = await self.read_frame(max_size)
  File "/Users/peurrr/Desktop/sample/env/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 1170, in read_frame
    frame = await Frame.read(
  File "/Users/peurrr/Desktop/sample/env/lib/python3.9/site-packages/websockets/legacy/framing.py", line 69, in read
    data = await reader(2)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/streams.py", line 721, in readexactly
    raise exceptions.IncompleteReadError(incomplete, n)
asyncio.exceptions.IncompleteReadError: 0 bytes read on a total of 2 expected bytes

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/peurrr/Desktop/sample/env/lib/python3.9/site-packages/pyppeteer/connection.py", line 73, in _async_send
    await self.connection.send(msg)
  File "/Users/peurrr/Desktop/sample/env/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 635, in send
    await self.ensure_open()
  File "/Users/peurrr/Desktop/sample/env/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 944, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: no close frame received or sent

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/peurrr/Desktop/sample/env/lib/python3.9/site-packages/pyppeteer/connection.py", line 79, in _async_send
    await self.dispose()
  File "/Users/peurrr/Desktop/sample/env/lib/python3.9/site-packages/pyppeteer/connection.py", line 170, in dispose
    await self._on_close()
  File "/Users/peurrr/Desktop/sample/env/lib/python3.9/site-packages/pyppeteer/connection.py", line 151, in _on_close
    cb.set_exception(_rewriteError(
asyncio.exceptions.InvalidStateError: invalid state
@ajatkj
Copy link

ajatkj commented May 12, 2023

Seems like Chromium is crashing because pyppeteer uses a very old version of Chromium by default. Try installing latest version of Chromium by setting PYPPETEER_CHROMIUM_REVISION to the latest revision.
You can find the latest revision from here.

I can run below code without any issues (I am on latest version of Chromium browser).

import asyncio

from pyppeteer import launch


async def main():
    browser = await launch(headless=False)
    page = await browser.newPage()
    # Do your thing
    await browser.close()


asyncio.run(main())

@G-Guillard
Copy link

G-Guillard commented May 26, 2023

I had the same issue (actually, the readme example would trigger an infinite loop without error message, the browser acting as if it had no internet connection).

@ajatkj's answer seems spot on, since it worked fine after

$ export PYPPETEER_CHROMIUM_REVISION=1149569
$ pyppeteer-install

However I noticed afterwards the somehow discreet warning on top of the readme :

Attention: This repo is unmaintained and has been outside of minor changes for a long time. Please consider playwright-python as an alternative.

It might be worth considering.

@cboin1996
Copy link

I made a fork that uses playwright under the hood. see: https://github.com/cboin1996/requests-html

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