I’m working on a project that bundles a repo to an .exe using Node SEA. Bundling puppeteer causes me to need to install chrome myself, so I’ve switched from puppeteer
to puppeteer-core
+ @puppeteer/browsers
. Currently, I’m just trying to get a local chrome install to work, but I’m getting a 404:
Error in main function: Error: Got status code 404
at C:UsersuserOneDriveDesktopcore changesnode_modules@puppeteerbrowserslibcjshttpUtil.js:135:31
at ClientRequest.requestCallback (C:UsersuserOneDriveDesktopcore changesnode_modules@puppeteerbrowserslibcjshttpUtil.js:72:13)
at Object.onceWrapper (node:events:634:26)
at ClientRequest.emit (node:events:519:28)
I think there’s an issue with my installation options however, b/c the pptr dev documentation provides no context for valid values (https://pptr.dev/browsers-api/browsers.installoptions) and b/c I can’t find an example online with string values assigned to these option variables (https://github.com/puppeteer/puppeteer/issues/10425), I’m not sure what specifically is causing the problem. Any help is appreciated!
const fs = require('node:fs');
const path = require('node:path');
const puppeteerBrowsers = require('@puppeteer/browsers');
const puppeteer = require('puppeteer-core');
const cacheDir = path.join(os.homedir(), '.CSVtoPDF', 'cache');
if(!fs.existsSync(cacheDir)){
fs.mkdirSync(path.join(os.homedir(), '.CSVtoPDF'));
fs.mkdirSync(cacheDir);
}
const installedBrowsers = await puppeteerBrowsers.getInstalledBrowsers({cacheDir});
if(installedBrowsers.length === 0){
let browserInfo = await puppeteerBrowsers.install({
browser: 'chrome',
buildId: '1300313',
cacheDir,
});
}
// puppeteer-core stuff
Chrome versions: https://googlechromelabs.github.io/chrome-for-testing/#stable
By locating the browser previously installed by puppeteer
and console.log’ing its contents I was able to confirm that the buildId format was the issue.
eg
[
InstalledBrowser {
browser: 'chrome-headless-shell',
buildId: '126.0.6478.126',
platform: 'win64',
executablePath: 'C:\Users\user\.CSVtoPDFv1.07\cache\chrome-headless-shell\win64-126.0.6478.126\chrome-headless-shell-win64\chrome-headless-shell.exe'
}
]
the String needs to reflect is exact Chrome version number: eg ‘126.0.6478.126’. The other valid values for browser and platform are listed in the docs:
https://pptr.dev/browsers-api/browsers.browser
https://pptr.dev/browsers-api/browsers.browserplatform