【问题标题】:Issue Running Google Lighthouse in Docker Container在 Docker 容器中运行 Google Lighthouse 的问题
【发布时间】:2021-01-24 16:11:07
【问题描述】:

我正在尝试在 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

【问题讨论】:

    标签: amazon-web-services docker google-chrome lambda lighthouse


    【解决方案1】:

    要在 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);
    

    但是,我在性能类别中遇到错误,无法使其正常工作,所有其他类别都可以正常工作。

    【讨论】:

      猜你喜欢
      • 2023-01-25
      • 2021-07-14
      • 2018-08-07
      • 1970-01-01
      • 2021-03-04
      • 1970-01-01
      • 1970-01-01
      • 2023-02-02
      • 2020-11-22
      相关资源
      最近更新 更多