我正在尝试使用puppeteer-core
和chrome-aws-lambda
,以便可以将函数上传到aws lambda,但是在本地运行脚本时出现错误,我尝试卸载并重新安装模块,但是我仍然收到错误,这是我的代码
const chrome = require('chrome-aws-lambda');
const puppeteer = require('puppeteer-core');
(async () => {
const browser = await puppeteer.launch({
args: chrome.args,
executablePath: "/home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br",
headless: chrome.headless,
});
const page = await browser.newPage();
await page.goto('https://example.com');
await browser.close();
})();
它给了我这个错误,我不确定该怎么做
(node:17811) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
/home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: 1: /home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: ���m�����鹲o�b�Vb%�]!yb: not found
/home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: 1: /home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: �6��d�11�l��L���: not found
/home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: 1: /home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: cannot open c: No such file
/home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: 1: /home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: i��D-mPL�-X�R: not found
/home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: 1: /home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: U�#.: not found
/home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: 2: /home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: Syntax error: ")" unexpected
TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
at onClose (/home/connor/Desktop/serverless/node_modules/puppeteer-core/lib/Launcher.js:342:14)
at Interface.helper.addEventListener (/home/connor/Desktop/serverless/node_modules/puppeteer-core/lib/Launcher.js:331:50)
at Interface.emit (events.js:198:15)
at Interface.close (readline.js:394:8)
at Socket.onend (readline.js:172:10)
at Socket.emit (events.js:198:15)
at endReadableNT (_stream_readable.js:1139:12)
at processTicksAndRejections (internal/process/task_queues.js:81:17)
(node:17811) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:17811) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
答案 0 :(得分:0)
puppeteer-core
软件包不同, chrome
不包括puppeteer
安装。
如果您希望在Lambda中使用puppeteer
,请尝试使用已经为您提供chrome
的Lambda图层,例如https://github.com/RafalWilinski/serverless-puppeteer-layers。