本文介绍了可以在Google云端功能中运行无头Chrome / Chromium?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法运行在谷歌云功能?我知道我可以在GCF中包含并运行静态编译的二进制文件。我可以得到一个静态编译版本的Chrome吗?
解决方案
我刚刚部署了一个运行无头的GCF函数铬。一对夫妇:
- 您必须在Debian 8上静态编译Chromium和NSS
- 在启动Chromium之前将环境变量修补为指向NSS
- 的性能比您在AWS Lambda上获得的性能差得多(3+秒)
- you have to statically compile Chromium and NSS on Debian 8
- you have to patch environment variables to point to NSS before launching Chromium
- performance is much worse than what you'd get on AWS Lambda (3+ seconds)
ol>
对于1,您应该能够在网上找到大量说明。
对于2, m使用如下:
static executablePath(){
let bin = path.join(__ dirname,'。 ','bin','chromium');
let nss = path.join(__ dirname,'..','bin','nss','Linux3.16_x86_64_cc_glibc_PTH_64_OPT.OBJ');
if(process.env.PATH === undefined){
process.env.PATH = path.join(nss,'bin');
} else if(process.env.PATH.indexOf(nss)=== -1){
process.env.PATH = [path.join(nss,'bin'),process.env 。路径]。加入( ':');
}
if(process.env.LD_LIBRARY_PATH === undefined){
process.env.LD_LIBRARY_PATH = path.join(nss,'lib');
} else if(process.env.LD_LIBRARY_PATH.indexOf(nss)=== -1){
process.env.LD_LIBRARY_PATH = [path.join(nss,'lib'),process.env .LD_LIBRARY_PATH]。加入( ':');
}
if(fs.existsSync('/ tmp / chromium')=== true){
return'/ tmp / chromium';
返回新的Promise(
(resolve,reject)=> {
try {
fs.chmod(bin,'0755', ()=> {
fs.symlinkSync(bin,'/ tmp / chromium'); return resolve('/ tmp / chromium');
});
} catch(error ){
return reject(error);
}
}
);
}
启动Chrome时还需要使用一些必需的参数,即:
- disable-dev-shm-usage
--disable-setuid-sandbox
--no -first-run
--no-sandbox
--no-zygote
--single-process
我希望这有助于。
Is there any way to run Headless Chrome/Chromium in a Google Cloud Function? I understand I can include and run statically compiled binaries in GCF. Can I get a statically compiled version of Chrome that would work for this?
解决方案
I've just deployed a GCF function running headless Chrome. A couple takeways:
For 1, you should be able to find plenty of instructions online.
For 2, the code that I'm using is the following:
static executablePath() {
let bin = path.join(__dirname, '..', 'bin', 'chromium');
let nss = path.join(__dirname, '..', 'bin', 'nss', 'Linux3.16_x86_64_cc_glibc_PTH_64_OPT.OBJ');
if (process.env.PATH === undefined) {
process.env.PATH = path.join(nss, 'bin');
} else if (process.env.PATH.indexOf(nss) === -1) {
process.env.PATH = [path.join(nss, 'bin'), process.env.PATH].join(':');
}
if (process.env.LD_LIBRARY_PATH === undefined) {
process.env.LD_LIBRARY_PATH = path.join(nss, 'lib');
} else if (process.env.LD_LIBRARY_PATH.indexOf(nss) === -1) {
process.env.LD_LIBRARY_PATH = [path.join(nss, 'lib'), process.env.LD_LIBRARY_PATH].join(':');
}
if (fs.existsSync('/tmp/chromium') === true) {
return '/tmp/chromium';
}
return new Promise(
(resolve, reject) => {
try {
fs.chmod(bin, '0755', () => {
fs.symlinkSync(bin, '/tmp/chromium'); return resolve('/tmp/chromium');
});
} catch (error) {
return reject(error);
}
}
);
}
You also need to use a few required arguments when starting Chrome, namely:
--disable-dev-shm-usage
--disable-setuid-sandbox
--no-first-run
--no-sandbox
--no-zygote
--single-process
I hope this helps.
这篇关于可以在Google云端功能中运行无头Chrome / Chromium?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!