小编sha*_*ked的帖子

firebase 函数 Puppeteer 找不到 Chromium GCP

我已经在谷歌云上使用GCP很长时间了,我想运行一个使用Puppeteer的云函数,但不幸的是,我收到以下错误。


未处理的错误错误:找不到 Chromium(修订版 1069273)。如果出现以下任一情况,就会发生这种情况

  1. 您在运行脚本之前没有安装(例如,npm install)或
  2. 您的缓存路径配置不正确(即:/root/.cache/puppeteer)。对于 (2),请查看我们的 Puppeteer 配置指南,网址为https://pptr.dev/guides/configuration。在 ChromeLauncher.resolveExecutablePath (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:120:27) 在 ChromeLauncher.executablePath (/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/节点/ChromeLauncher.js:166:25)在ChromeLauncher.launch(/workspace/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:70:37)在异步/workspace/lib/index.js :122:21在异步/workspace/node_modules/firebase-functions/lib/common/providers/https.js:407:26

我的代码是


export const test = functions
  .runWith({
    timeoutSeconds: 120,
    memory: "512MB" || "2GB",
  })
  .https.onCall(async (data, context) => {
    const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
    const page = await browser.newPage();
    await page.goto("https://www.google.com/");

    browser.close();
    return { msg: "all good", status: 200 };
  });

Run Code Online (Sandbox Code Playgroud)

我从这里复制了如何在 GCP 功能中使用 Puppeteer 的示例(在我的机器上工作),我还尝试了不使用 Puppeteer 的其他功能,效果很好(所以我确信问题出在 Puppeteer 上)。我还尝试添加标志“--disable-setuid-sandbox”,但这不起作用。我正在用 Typescript 编写 firebase 函数。我的 package.json …

node.js firebase google-cloud-functions puppeteer

16
推荐指数
2
解决办法
5085
查看次数