Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Error: Could not find expected browser (chrome) locally. Run npm install to download the correct Chromium revision (901912). #296

Open
kurtsys opened this issue Jun 23, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@kurtsys
Copy link

kurtsys commented Jun 23, 2023

Environment

  • chrome-aws-lambda Version: "^10.1.0",
  • puppeteer / puppeteer-core Version: "puppeteer-core": "^10.1.0"
  • OS: amazon linux
  • Lambda / GCF Runtime: Node.js 14.x

Expected Behavior

Puppeteer launching when AWS lambda starts.

Current Behavior

Error: AWS lambda doesn't find the (correct) chromium browser.

START RequestId: 50e21a5f-c30b-400e-97d6-a0124de70d1c Version: $LATEST
--
2023-06-23T06:48:02.530Z	50e21a5f-c30b-400e-97d6-a0124de70d1c	INFO	Starting test run with SESSION ID: 6b9070a5-55a0-43e9-b2d3-2d3fb63d3ba9
2023-06-23T06:48:02.530Z	50e21a5f-c30b-400e-97d6-a0124de70d1c	ERROR	An exception occurred during judgement...
2023-06-23T06:48:02.530Z	50e21a5f-c30b-400e-97d6-a0124de70d1c	ERROR	Error: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (901912).    at ChromeLauncher.launch (/var/task/node_modules/puppeteer-core/lib/cjs/puppeteer/node/Launcher.js:88:27)    at async newPage (file:///var/task/index.js:28:19)    at async Runtime.handler (file:///var/task/index.js:123:12)
2023-06-23T06:48:02.530Z	50e21a5f-c30b-400e-97d6-a0124de70d1c	INFO	[...]
2023-06-23T06:48:02.625Z	50e21a5f-c30b-400e-97d6-a0124de70d1c	INFO	Shutting down judge...
2023-06-23T06:48:02.625Z	50e21a5f-c30b-400e-97d6-a0124de70d1c	INFO	Judge is shut down...

The code

package.json:

{
  "name": "@ftrprf/scratch-judge-serverless-api-aws",
  "private": "true",
  "version": "0.0.1",
  "type": "module",
  "scripts": {
    "start": "node src/index.js",
    "clean": "rm -rf dist dist.zip node_modules",
    "build": "rm -rf dist dist.zip && cpy --cwd=src --parents '**/*' '!**/*.ts' ../dist/ && cpy ./package.json dist/",
    "package": "npm prune --production && npm dedupe --production && zip -r dist.zip node_modules && cd dist && zip -ur ../dist.zip . && cd -",
    "aws:upload": "npm run package && aws s3 cp ./dist.zip s3://ftrprf-bucket-builds/$npm_package_name/branches/$BRANCH_NAME.zip",
    "test": "NODE_OPTIONS=--experimental-vm-modules npx jest test/test.js"
  },
  "dependencies": {
    "@converse/openpromise": "^0.0.1",
    "@ftrprf/judge-core": "^1.8.0",
    "@ftrprf/judge-runner": "^1.8.0",
    "busboy": "^0.3.1",
    "chrome-aws-lambda": "^10.1.0",
    "dotenv": "^10.0.0",
    "lodash-es": "^4.17.21",
    "mergebounce": "^0.1.1",
    "node-fetch": "^3.2.10",
    "puppeteer-core": "^10.1.0"
  },
  "devDependencies": {
    "cpy-cli": "^3.1.1",
    "jest": "^29.1.2",
    "node-static": "^0.7.11",
    "prettier": "^2.8.8",
    "puppeteer": "^10.1.0",
    "msw": "^1.2.1"
  },
  "prettier": {
    "singleQuote": true,
    "printWidth": 110
  }
}

index.js:

import fetch from 'node-fetch';

import chromium from 'chrome-aws-lambda';
import { puppeteerOptions } from './utils/puppeteer-options.js';
[...]

/** @type Promise<Browser> | null */
let globalBrowser = null;

/**
 * @returns {Promise<Page>}
 */
async function newPage(headless = true) {
  if (globalBrowser === null) {
    const path = await chromium.executablePath;
    globalBrowser = chromium.puppeteer.launch({
      ...puppeteerOptions,
      headless,
      path,
    });
  }

  const browser = await globalBrowser;
  return await browser.newPage();
}

[...]

export async function handler(event, _context) {
  ...
  try {
    page = await newPage(event.test);
    await page.setBypassCSP(true);

    // Link page errors
    const errorPromise = new Promise((resolve, reject) => {
      page.on('error', reject);
      page.on('pageerror', reject);
    });

    timeoutPromise = sleep(55000).then(() => {
      if (running) {
        console.error('Aborted the test runner after 60s');

        throw new Error('timeout');
      }
    });

    [...]

    console.log('Judge is shut down...');
  }

  return response;
}
@kurtsys kurtsys added the bug Something isn't working label Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant