gpt4 book ai didi

pdf-generation - 无法启动 Chrome!使用 Puppeteer 时 spawn ...node_modules/puppeteer/.../chrome ENOENT 故障排除

转载 作者:行者123 更新时间:2023-12-03 23:53:06 31 4
gpt4 key购买 nike

我试图构建一个快速 lambda 来打印带有特定 url 的 pdf,但我收到此错误:无法启动 Chrome!生成 ...node_modules/puppeteer/.../chrome ... 故障排除
这里提到的方法:https://github.com/GoogleChrome/puppeteer/issues/807#issuecomment-366529860没有帮助我。
我正在使用的代码:

    const browser = await puppeteer.launch({
headless: true,
executablePath: '../../node_modules/puppeteer/.local-chromium/linux-624487/chrome-linux/chrome',
args: ['--no-sandbox', '--disable-setuid-sandbox'],
});
try {
const result = await exports.run(browser);
callback(null, result);
} catch (e) {
callback(e);
}

...

exports.run = async (browser) => {
// implement here
// this is sample
const page = await browser.newPage();
await page.goto('https://www.google.com', {
waitUntil: ['domcontentloaded', 'networkidle0']
});
console.log((await page.content()).slice(0, 500));

await page.type('#lst-ib', 'aaaaa');
// avoid to timeout waitForNavigation() after click()
await Promise.all([
// avoid to
// 'Cannot find context with specified id undefined' for localStorage
page.waitForNavigation(),
page.click('[name=btnK]'),
]);

// cookie and localStorage
await page.setCookie({
name: 'name',
value: 'cookieValue'
});
console.log(await page.cookies());
console.log(await page.evaluate(() => {
localStorage.setItem('name', 'localStorageValue');
return localStorage.getItem('name');
}));
const result = await page.pdf({
path: 'hn.pdf',
format: 'A4'
});
console.log(` typeof : ${typeof result}, pdf: ${result}`);
await page.close();
return 'done';
};

最佳答案

检查此路径 =>
\node_modules\puppeteer.local-chromium\win32-818858\chrome-win
您会注意到 chrome.exe 将不存在,现在又退回了一步 =>
*\node_modules\puppeteer.local-chromium*
您会发现 zip 文件“chrome-win”将其解压缩并将其移动到 =>
\node_modules\puppeteer.local-chromium\win32-818858
现在您可以检查它是否有效。

关于pdf-generation - 无法启动 Chrome!使用 Puppeteer 时 spawn ...node_modules/puppeteer/.../chrome ENOENT 故障排除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54538306/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com