在Docker容器中运行Google Lighthouse的问题



我正在尝试在Docker容器中运行lighthouse,以便最终部署到AWS Lambda(使用其新的Docker映像Lambda部署)。然而,我得到一个错误,我似乎不能理解。

以下是我的dockerfile

FROM amazon/aws-lambda-nodejs:12
ENV AWS_LAMBDA_FUNCTION_MEMORY_SIZE=10240
RUN curl https://intoli.com/install-google-chrome.sh | bash
copy package.json .
RUN npm install
COPY app.js .
CMD ["app.handler"]
以下是我的app.js
const chromeLauncher = require("chrome-launcher");
const lighthouse = require("lighthouse");
exports.handler = async (event) => {
const chrome = await chromeLauncher.launch({
logLevel: "info",
chromeFlags: [
"--headless",
"--no-sandbox",
"--disable-gpu",
"--disable-dev-shm-usage",
"--single-process",
],
});
const results = await lighthouse("https://example.com", {
port: chrome.port,
disableStorageReset: true,
onlyCategories: ["performance"],
logLevel: "info",
});
return {
statusCode: 200,
results,
};
};

,日志输出如下。它似乎可以连接到灯塔,但它在发送的第一个命令/

上挂起了
START RequestId: c9d7a07b-a5e2-4d03-8bf5-d0b5d248e3e7 Version: $LATEST
Sun, 24 Jan 2021 16:00:56 GMT ChromeLauncher Waiting for browser.
Sun, 24 Jan 2021 16:00:56 GMT ChromeLauncher Waiting for browser...
Sun, 24 Jan 2021 16:00:57 GMT ChromeLauncher Waiting for browser.....
Sun, 24 Jan 2021 16:00:57 GMT ChromeLauncher Waiting for browser.....✓
Sun, 24 Jan 2021 16:00:58 GMT status Connecting to browser
Sun, 24 Jan 2021 16:00:58 GMT status Resetting state with about:blank
Sun, 24 Jan 2021 16:01:28 GMT status Disconnecting from browser...
2021-01-24T16:01:28.172Z        c9d7a07b-a5e2-4d03-8bf5-d0b5d248e3e7    ERROR      Invoke Error    {"errorType":"LHError","errorMessage":"PROTOCOL_TIMEOUT","code":"PROTOCOL_TIMEOUT","name":"LHError","friendlyMessage":"Waiting for DevTools protocol response has exceeded the allotted time. (Method: Network.enable)","lhrRuntimeError":true,"protocolMethod":"Network.enable","stack":["LHError: PROTOCOL_TIMEOUT","    at Timeout._onTimeout (/var/task/node_modules/lighthouse/lighthouse-core/gather/driver.js:409:21)","    at listOnTimeout (internal/timers.js:554:17)","    at processTimers (internal/timers.js:497:7)"]}
END RequestId: c9d7a07b-a5e2-4d03-8bf5-d0b5d248e3e7
REPORT RequestId: c9d7a07b-a5e2-4d03-8bf5-d0b5d248e3e7  Init Duration: 3.53 ms     Duration: 33422.31 ms   Billed Duration: 33500 ms       Memory Size: 2010240 MB    Max Memory Used: 2010240 MB

要在AWS Function Lambda上运行,应该使用

const chromium = require("chrome-aws-lambda");
const chrome = await chromium.puppeteer.launch({
args: [
...chromium.args,
"--disable-dev-shm-usage",
"--remote-debugging-port=9222",
],
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const options = {
logLevel: "info",
output: "html",
onlyCategories: ["performance"],
preset: "mobile",
port: 9222,
};
const runnerResult = await lighthouse(`${body.url}`, options);

但是,我在性能类别中遇到了错误,没有办法使它工作,所有其他类别都工作良好。

最新更新