Ayu*_*udh 2 node.js google-cloud-functions puppeteer
Puppeteer 无法在谷歌云中工作!
镀铬错误如图所示。
我已经在这里实现了建议:Puppeteer error on Heroku: Could not find Chromium
我还尝试将我的 puppeteer 版本从 19.x 降级到 18.x 和 17.x,但没有成功。
我会尝试使用剧作家,除非这里有人知道如何解决这个问题......
编辑:我尝试使用 puppeteer-chromium-resolver 而不是 puppeteer,但是现在我完全无法在节点运行时 16 和 18 上部署我的云功能。
编辑2:我放弃了 puppeteer-chromium-resolver,转而使用 chrome-aws-lambda,并添加了以下代码片段并部署到 Google 云函数:
const bundledChromium = require('chrome-aws-lambda');
const playwright = require('playwright-core');
(async () => {
const browser = await Promise.resolve(bundledChromium.executablePath).then(
(executablePath) => {
console.log("executablePath: ", executablePath);
if (!executablePath) {
// local execution
return playwright.chromium.launch({});
}
return playwright.chromium.launch({ executablePath });
}
);
})()
Run Code Online (Sandbox Code Playgroud)
该语句console.log("executablePath: ", executablePath);打印“/tmp/chromium”
但是我收到另一个错误:
2022-12-27 15:12:00.281 HKT
function-1ol6uqbjimrh1 Function execution started
2022-12-27 15:12:00.295 HKT
function-1ol6uqbjimrh1 executablePath: /tmp/chromium
2022-12-27 15:12:00.305 HKT
function-1ol6uqbjimrh1 Function execution took 24 ms, finished with status: 'ok'
2022-12-27 15:12:00.414 HKT
function-1ol6uqbjimrh1 browserType.launch: spawn EFAULT
2022-12-27 15:12:00.414 HKT
function-1ol6uqbjimrh1 =========================== logs ===========================
2022-12-27 15:12:00.414 HKT
function-1ol6uqbjimrh1 <launching> /tmp/chromium --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-K9OYeC --remote-debugging-pipe --no-startup-window
2022-12-27 15:12:00.414 HKT
function-1ol6uqbjimrh1 ============================================================
2022-12-27 15:12:00.414 HKT
function-1ol6uqbjimrh1 at /workspace/index.js:37:25
2022-12-27 15:12:00.414 HKT
function-1ol6uqbjimrh1 at async main (/workspace/index.js:30:21) {
2022-12-27 15:12:00.414 HKT
function-1ol6uqbjimrh1 name: 'Error'
2022-12-27 15:12:00.414 HKT
function-1ol6uqbjimrh1 }
Run Code Online (Sandbox Code Playgroud)
不知道如何从这里继续......
最终编辑:我尝试在 ECR 中使用 AWS lambda 和 puppeteer,但这也不起作用,所以我在 pythonanywhere.com 上使用 python selenium。整个经历令人沮丧,但至少硒有效。
以下是 github 的链接,了解更多详细信息:https ://github.com/Sparticuz/chromium/issues/29
小智 5
.puppeteerrc.cjs和更改默认缓存目录。const { join } = require("path");
/**
* @type {import("puppeteer").Configuration}
*/
module.exports = {
// Changes the cache location for Puppeteer.
cacheDirectory: join(__dirname, ".cache", "puppeteer"),
};
Run Code Online (Sandbox Code Playgroud)
.puppeteerrc.cjs,需要重新安装 puppeteer 软件包,因此您必须从 GCP 中删除您的函数,然后重新部署您的函数。| 归档时间: |
|
| 查看次数: |
2286 次 |
| 最近记录: |