首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Docker Container中运行Google Lighthouse的问题

在Docker Container中运行Google Lighthouse的问题
EN

Stack Overflow用户
提问于 2021-01-25 00:11:08
回答 1查看 524关注 0票数 2

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

以下是我的dockerfile

代码语言:javascript
复制
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

代码语言:javascript
复制
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,
  };
};

以下是日志输出。它似乎能够连接到灯塔,但随后在它发送的第一个命令时挂起/

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2021-07-25 00:08:48

要在AWS函数Lambda上运行,您应该使用

代码语言:javascript
复制
    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);

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65872890

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档