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

pyppeteer Browser closed unexpectedly #442

Open
MominIqbal-1234 opened this issue Jun 9, 2023 · 4 comments
Open

pyppeteer Browser closed unexpectedly #442

MominIqbal-1234 opened this issue Jun 9, 2023 · 4 comments

Comments

@MominIqbal-1234
Copy link

MominIqbal-1234 commented Jun 9, 2023

i use Linux machine and chromium install sucessfully
when i run script so return this error

My Code:

import asyncio
from pyppeteer import launch

async def scrape_website(url):
browser = await launch()
page = await browser.newPage()
await page.goto(url)
html_content = await page.content()
# await browser.close()
return html_content

URL of the website you want to scrape

website_url = 'https://example.com/'

Run the scraping function

html_content = asyncio.get_event_loop().run_until_complete(scrape_website(website_url))

Print the HTML content

print(html_content)

Traceback (most recent call last):
File "/pythoncode/main.py", line 16, in
html_content = asyncio.get_event_loop().run_until_complete(scrape_website(website_url))
File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
return future.result()
File "/pythoncode/main.py", line 5, in scrape_website
browser = await launch()
File "/usr/local/lib/python3.10/dist-packages/pyppeteer/launcher.py", line 307, in launch
return await Launcher(options, **kwargs).launch()
File "/usr/local/lib/python3.10/dist-packages/pyppeteer/launcher.py", line 168, in launch
self.browserWSEndpoint = get_ws_endpoint(self.url)
File "/usr/local/lib/python3.10/dist-packages/pyppeteer/launcher.py", line 227, in get_ws_endpoint
raise BrowserError('Browser closed unexpectedly:\n')
pyppeteer.errors.BrowserError: Browser closed unexpectedly:

@sergeyyurkov1
Copy link

sergeyyurkov1 commented Jun 28, 2023

This error usually indicates missing dependencies. Try installing libxtst6 with apt or your distribution's equivalent. Check if anything else is missing by running the following command: ldd /root/.local/share/pyppeteer/local-chromium/588429/chrome-linux/chrome | grep "not found" (the path on your machine may differ). Additionally, you may need to pass args=["--no-sandbox"] argument to the await launch() function.

@sergeyyurkov1
Copy link

Although Pyppeteer guys don't recommend this approach because of possible version incompatibilities, you can try the following:

  1. Install chromium-browser (Ubuntu) or chromium (Debian) with apt or equivalent
  2. Locate Chromium executable with whereis chromium and copy the first path you see
  3. Pass executablePath="YOUR PATH" into the launch function

Tested on Debian Buster.

@kdudyala
Copy link

Hi Team
I am also facing same issue. I have passed additional arguments to launch function.
browser = await launch(headless=True,
args=['--no-sandbox', '--disable-dev-shm-usage', '--disable-gpu', '--disable-software-rasterizer', '--disable-setuid-sandbox'])
In local I am not facing same issue but when we deploy it the issue occurs continuously. Please suggest.

@GregKarabinos
Copy link

I am facing this issue as well. It is a big blocker for me.

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