gpt4 book ai didi

Deploying firebase function with puppeteer says chrome can't be found even thoough I have enabled --no-sandbox(使用木偶操纵者部署Firebase功能时说,即使我启用了--no-Sandbox,也找不到Chrome)

转载 作者:bug小助手 更新时间:2023-10-28 13:22:53 27 4
gpt4 key购买 nike



I'm trying to deploy a firebase function to my firebase project that use puppeteer, I have it working on my local machine, but when it tries running on firebase I get this error:

我正在尝试将一个Firebase函数部署到使用Pupeteer的FireBase项目中,我让它在我的本地计算机上运行,但当它尝试在FireBase上运行时,我收到以下错误:


"Exception from a finished function: Error: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (1045629)."

I've saw other people online saying to use the --no-sand box flag, which I have already tried but it's still throwing this error

我在网上看到其他人说要使用--no-沙箱标志,我已经尝试过了,但它仍然抛出这个错误


This is my code for initializing puppeteer:

这是我初始化puppeteer的代码:


  browser = await puppeteer.launch({
headless: true,
args: ["--no-sandbox", "--disable-setuid-sandbox"],
});

The node version is set to 16 in my package.json and puppeteer is version 19.0.0

在我的Package.json中,节点版本设置为16,而puppeteer的版本为19.0.0


I would greatly appreciate any help! Thanks!

如有任何帮助,我将不胜感激!谢谢!


更多回答

In version 19.0.0, the browser location folder has changed to ~/.cache/puppeteer instead of node_modules. Is it possible for you to verify if the browser is downloaded there? Also, if you run your function with the env variable DEBUG=puppeteer:*, the log should give more info about what goes wrong.

在19.0.0版中,浏览器位置文件夹已更改为~/.cache/puppeteer,而不是node_MODULES。您是否可以验证是否在那里下载了浏览器?此外,如果使用环境变量DEBUG=puppeteer:*运行函数,日志应该会给出更多有关错误的信息。

As suggested in this github try running this command node node_modules/puppeteer/install.js

按照此GitHub中的建议,尝试运行命令node node_MODULES/puppeteer/install.js

I'm getting this exact same issue. Sathi when I run that command I just get the message "Chromium is already in C:\Users\me\.cache\puppeteer\chrome\win64-1045629; skipping download."

我也收到了同样的问题。当我运行该命令时,我只收到消息“Chromium已在C:\Users\me\.cache\puppeteer\chrome\win64-1045629;中跳过下载”。

I have the same problem. Did you fix it?

我也有同样的问题。你修好了吗?

I ended up using heroku, cause there was only one extra step to get it working where it was just searching / linking for the puppeteer package, but my server ran out of memory. Puppeteer seems to be really convoluted for some certain things. I think using selenium with python is honestly the best way to go for automation type stuff like this.

我最终使用了Heroku,因为只需多一个步骤就可以让它正常工作,它只是搜索/链接木偶操纵者程序包,但我的服务器内存不足。木偶师似乎对某些事情真的很费解。我认为,将Selence与Python结合使用是处理这种自动化类型的东西的最好方式。

优秀答案推荐

I ran into the same issue and was able to resolve it by installing puppeteer at the earlier 18.2.1 version (npm i [email protected]). I think the error is a result of this -> https://pptr.dev/guides/configuration/

我遇到了同样的问题,并能够通过安装较早的18.2.1版本(NPM I[电子邮件受保护])的木偶操纵者来解决它。我认为错误是由以下原因造成的->https://pptr.dev/guides/configuration/



I ran into similar problem on M1 Mac. Puppeteer could not find Chrome because Firebase Functions run on linux, and puppeteer downloaded only Mac version.

我在M1Mac上遇到了类似的问题。Pupeteer找不到Chrome,因为Firebase功能在Linux上运行,而Pupeteer只下载了Mac版本。


I moved puppeteer's cache into project folder to make sure it is included into the build package, and set up a script to automatically download Chrome for linux on every deploy.

我将Pupeteer的缓存移到了项目文件夹中,以确保它包含在构建包中,并设置了一个脚本来在每次部署时自动下载Chrome for Linux。


.puppeteerrc.cjs. Moved cacheDirectory to the project folder.

.puppeteerrc.cjs。已将cacheDirectory移至项目文件夹。


const { join } = require('path');

/**
* @type {import("puppeteer").Configuration}
*/
module.exports = {
cacheDirectory: join(__dirname, '.cache', 'puppeteer'),
};

util/puppeteer-downloader.js. This script downloads Chrome specific for the installed puppeteer version and places it into cacheDirectory specified above.

Util/puppeteer-downloader.js.此脚本下载特定于已安装的木偶剧版本的Chrome,并将其放入上面指定的cacheDirectory中。


const { PUPPETEER_REVISIONS } = require('puppeteer-core');
const { install } = require('@puppeteer/browsers');
const config = require('../.puppeteerrc.cjs');

const buildId = PUPPETEER_REVISIONS.chrome;
const cacheDir = config.cacheDirectory;

async function downloadChrome(platform) {
console.log('Installing Chrome version', buildId, 'for platform', platform, 'to', cacheDir);
try {
await install({ platform, browser: 'chrome', buildId, cacheDir });
console.log('Chrome installed successfully');
} catch (err) {
console.error('Chrome installation failed', err);
throw err;
}
}

(async () => {
await downloadChrome('linux');
})().catch(() => process.exit(1));

firebase.json. Clears .cache folder to make sure only linux version is installed. Otherwise other versions also will be included into deploy package, bloating it and wasting Firebase storage and bandwidth quotas.

Firebase.json。清除.cache文件夹以确保仅安装了Linux版本。否则,其他版本也将被包括在部署包中,使其膨胀并浪费Firebase存储和带宽配额。


{
"functions": [
{
"source": ".",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"tsc",
"rm -rf .cache",
"node ./util/puppeteer-downloader.js"
]
}
]
}

This can be improved further to avoid re-downloading Chrome every time, but this is good enough for me for now.

这可以进一步改进,以避免每次重新下载Chrome,但这对我来说已经足够好了。


Packages:

套餐:


- firebase-functions: 4.4.1
- puppeteer: 21.1.1

更多回答

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