I'm a little new to deploying/hosting Node apps and Puppeteer.
But, I'm facing an issue though with my app on Heroku when trying to use Puppeteer.
The full error is:
Error: Could not find Chromium (rev. 1056772). This can occur if either
2022-11-10T06:44:07.938983+00:00 app[web.1]: 1. you did not perform an installation before running the script (e.g. `npm install`) or
2022-11-10T06:44:07.938983+00:00 app[web.1]: 2. your cache path is incorrectly configured (which is: /app/.cache/puppeteer).
2022-11-10T06:44:07.938983+00:00 app[web.1]: For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
2022-11-10T06:44:07.938984+00:00 app[web.1]: at ChromeLauncher.resolveExecutablePath (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:120:27)
2022-11-10T06:44:07.938984+00:00 app[web.1]: at ChromeLauncher.executablePath (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:166:25)
2022-11-10T06:44:07.938985+00:00 app[web.1]: at PuppeteerNode.executablePath (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/PuppeteerNode.js:162:105)
2022-11-10T06:44:07.938985+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:29:145)
2022-11-10T06:44:07.938985+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1159:14)
2022-11-10T06:44:07.938986+00:00 app[web.1]: at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
2022-11-10T06:44:07.938986+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:1037:32)
2022-11-10T06:44:07.938986+00:00 app[web.1]: at Module._load (node:internal/modules/cjs/loader:878:12)
2022-11-10T06:44:07.938986+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
2022-11-10T06:44:07.938987+00:00 app[web.1]: at node:internal/main/run_main_module:23:47
My code for index.js is:
const puppeteer = require('puppeteer-extra')
const RecaptchaPlugin = require('puppeteer-extra-plugin-recaptcha')
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
const { executablePath } = require('puppeteer')
const axios = require('axios')
//pupeteer plugins
puppeteer.use(
RecaptchaPlugin({
provider: {
id: '2captcha',
token: 'XXX'
},
visualFeedback: true //colorize reCAPTCHAs (violet = detected, green = solved)
})
)
puppeteer.use(StealthPlugin())
//pupeteer crawl
try {
puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'], headless: true, executablePath: executablePath(), ignoreHTTPSErrors: true }).then(async browser => {
console.log('Running tests..')
const page = await browser.newPage()
await page.goto('https://bot.sannysoft.com')
await page.setViewport({ width: 1680, height: 857 })
await page.waitForTimeout(5000)
await page.screenshot({ path: 'testresult.png', fullPage: true })
await browser.close()
console.log(`All done, check the screenshot. ✨`)
})
} catch (error) {
console.error(error);
}
And these are my build packs in Heroku:
I've been battling with these for a few days and tried everything :(
Thank you!!
I've tried adding the necessary flags:
args: ['--no-sandbox', '--disable-setuid-sandbox']
And also the build pack: https://github.com/jontewks/puppeteer-heroku-buildpack
These are the common solutions people have mentioned on other issue threads.