我正试图通过public.ecr.aws/lambda/nodejs
码头图片中的chrome-aws-lambda
运行灯塔,无论我发送到灯塔的哪个网站,我都会收到这样的错误:
Chrome在页面加载期间没有收集任何截图。请确认页面上有可见的内容,然后尝试重新运行灯塔.(NO_SCREENSHOTS)
请注意,我已经尝试过发送非常快的加载页面,如这,所以其他与此错误有关的提示,声称网站太慢对我来说似乎不正确。
/Dockerfile
FROM public.ecr.aws/lambda/nodejs:latest
RUN cd /var/task/ & npm install puppeteer-core chrome-aws-lambda lighthouse --save-prod
RUN cd /var/task/ & npm install puppeteer --save-dev
/docker-compose.yml
version: "3.5"
services:
lighthouse:
build:
context: .
networks:
- lighthousenetwork
ports:
- "8080:8080"
volumes:
- ./task/:/var/task/:delegated
command: index.handler
networks:
lighthousenetwork:
driver: bridge
/task/index.js
const chromium = require('chrome-aws-lambda');
const lighthouse = require('lighthouse');
exports.handler = async (event, context, callback) => {
let response = null;
let browser = null;
try {
browser = await chromium.puppeteer.launch({
args: [...chromium.args, "--remote-debugging-port=9222"],
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const options = {
output: "json",
preset: 'mobile',
onlyCategories: ["performance", "seo", "accessibility", "best-practices"],
port: 9222,
}
const url = 'https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event';
const result = await lighthouse(url, options);
console.log(`Audited ${url} in ${result.lhr.timing.total} ms.`);
const report = JSON.parse(result.report);
response = {
statusCode: 200,
body: {
'url': url,
'Performance': report['categories']['performance']['score'],
'Accessibility': report['categories']['accessibility']['score'],
'SEO': report['categories']['seo']['score'],
'BestPractices': report['categories']['best-practices']['score'],
'ErrorMessage': report['audits']['speed-index']['errorMessage']
}
}
} catch (error) {
return callback(error);
} finally {
if (browser !== null) {
await browser.close();
}
}
return callback(null, response);
};
启动Docker容器:
$ docker-compose up
触发函数处理程序:
$ curl -XPOST "http://localhost:8080/2015-03-31/functions/function/invocations" -d '{"payload":"hello world!"}'
输出:
{"statusCode":200,"body":{"url":"https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event","Performance":null,"Accessibility":0.91,"SEO":0.89,"BestPractices":1,"ErrorMessage":"Chrome didn't collect any screenshots during the page load. Please make sure there is content visible on the page, and then try re-running Lighthouse. (NO_SCREENSHOTS)"}}
发布于 2022-05-05 17:48:33
我遇到了同样的问题。做了很多事情,比如把不同的旗子传递到铬灯,灯塔。都不管用。
然后我找到了这个https://github.com/GoogleChrome/lighthouse/pull/10483/files#diff-b745a09f9adfeb967c49c66acad7fdcaR77
看来灯塔队并不是真的推荐兰达恩夫。
我看到其他ppl也遇到了同样的问题:https://github.com/GoogleChrome/lighthouse/issues/12101 https://github.com/GoogleChrome/lighthouse/issues/13021
是的,我建议暂时离开兰博达。试着在集群上运行灯塔什么的。
实际上并不是修复您所看到的错误的解决方案。但我只想分享一下我在这上面的发现。
https://stackoverflow.com/questions/71712808
复制相似问题