I recently deployed an app in heroku . It uses python pyppeteer package. I didnt had any issues while testing on repl.it. But unfortunately in heroku the browser keeps crashing.
I used requirement.txt for installing pyppeteer package. I also tried using apt heroku buildpack for installing the requirements needed for pupeteer to work as per here
My program :
async def mainer(link, path, is_image):
browser = await launch(args=['--no-sandbox'])
page = await browser.newPage()
await page.goto(link)
if is_image:
await page.screenshot({'path': f'{path}', 'fullPage': True, 'type': 'png'})
else:
await page.pdf({'path': f'{path}'})
await browser.close()
here is the full traceback error from heroku :
2020-05-14T19:39:50.115643+00:00 app[worker.1]: await handler.callback(self.client, *args)
2020-05-14T19:39:50.115644+00:00 app[worker.1]: File "/app/plugins/downloader.py", line 61, in cb_
2020-05-14T19:39:50.115645+00:00 app[worker.1]: await mainer(url,file,mode)
2020-05-14T19:39:50.115645+00:00 app[worker.1]: File "/app/plugins/downloader.py", line 13, in mainer
2020-05-14T19:39:50.115646+00:00 app[worker.1]: browser = await launch(args=['--no-sandbox'])
2020-05-14T19:39:50.115646+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/site-packages/pyppeteer/launcher.py", line 305, in launch
2020-05-14T19:39:50.115647+00:00 app[worker.1]: return await Launcher(options, **kwargs).launch()
2020-05-14T19:39:50.115648+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/site-packages/pyppeteer/launcher.py", line 166, in launch
2020-05-14T19:39:50.115648+00:00 app[worker.1]: self.browserWSEndpoint = get_ws_endpoint(self.url)
2020-05-14T19:39:50.115648+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/site-packages/pyppeteer/launcher.py", line 225, in get_ws_endpoint
2020-05-14T19:39:50.115649+00:00 app[worker.1]: raise BrowserError('Browser closed unexpectedly:\n')
2020-05-14T19:39:50.115649+00:00 app[worker.1]: pyppeteer.errors.BrowserError: Browser closed unexpectedly:
2020-05-14T19:39:50.115650+00:00 app[worker.1]:
If we care using the buildpack provided by Heroku, there will be an environmental variable called GOOGLE_CHROME_SHIM
. We can use this variable as an argument to pyppeteer.launch()
or webdriver.Chrome()
.