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

Incorrectly formed path to /bin/chromium.br' #270

Open
Facundojs opened this issue Apr 8, 2022 · 9 comments
Open

Incorrectly formed path to /bin/chromium.br' #270

Facundojs opened this issue Apr 8, 2022 · 9 comments

Comments

@Facundojs
Copy link

Im using chrome-aws-lambda and playwright-core just like the example. At the moment of usage of it in a serverless functions, i get the error "Error: ENOENT: no such file or directory, open '/var/task/src/scrapper/f_service/bin/chromium.br'\".
Also, i tried to add it in a layer wiht both libraries but still is failing.
This is my code:

import * as playwright from 'playwright-core';
import chromium from 'chrome-aws-lambda';

export const createBrowserContext: () => Promise<
  playwright.BrowserContext
> = async () => {
  const browser = await playwright.chromium.launch({
    args: chromium.args,
    executablePath: await chromium.executablePath',
    headless: chromium.headless,
  });
  return await browser.newContext();
};

This is how my dir looks like

.
├── layers
│   └── chromium
│       └── nodejs
├── resources
└── src
    ├── scrapper
    │   ├── freelancer
    │   │   ├── basic
    │   │   ├── check-service-state
    │   │   ├── record
    │   │   ├── emit-invoice
    │   │   ├── generate-vep
    │   │   ├── get-invoices
    │   │   ├── get-sale-points
    │   │   └── get-veps
    │   ├── workers
    │   │   ├── debt
    │   │   ├── basic
    │   │   ├── check-service-state
    │   │   └── generate-vep
    │   └── validate-credentials
    └── utils

My system

Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
CPU(s):                          12
Vendor ID:                       AuthenticAMD
CPU family:                      23
Model:                           8
Model name:                      AMD Ryzen 5 2600X Six-Core Processor
Distributor ID:	Ubuntu
Description:	Ubuntu 21.10
Release:	21.10

AWSLambda os is the default

@Soviut
Copy link

Soviut commented Apr 13, 2022

I had a similar issue with my function on Netlify where I needed to make sure chrome-aws-lambda as an external module.

netlify.toml

[functions.render]
  external_node_modules = ["chrome-aws-lambda"]

Perhaps you need one of the Lambda layers to make sure the module is loaded as well?

https://github.com/shelfio/chrome-aws-lambda-layer

tomoima525 added a commit to tomoima525/continuum that referenced this issue May 19, 2022
- addressing libsso missing issue with v16 alixaxel/chrome-aws-lambda#264
- Addressing the issue with chrome.br missing alixaxel/chrome-aws-lambda#270
@nwaguvictor
Copy link

Any solution to this yet?

@Facundojs
Copy link
Author

Yes, you have use lambda layers
In my case i zip a nodejs project for each package (Chrome anda playwright core), uploaded It as lambda layer and included It in serverless template
It should work easy

@nwaguvictor
Copy link

@Facundojs , can I get a repo example of how you used these modules in the lambda handler itself after separating the layers

@Facundojs
Copy link
Author

Assuming you included lambda layers as we talked, you should use a code as below, you can launch browser.
In local await chromium.executablePath will return null, thats why i use || {my-local-path}

import * as playwright from 'playwright-core';
import chromium from 'chrome-aws-lambda';

export const createBrowserContext: () => Promise<playwright.BrowserContext> =
  async () => {
    const browser = await playwright.chromium.launch({
      headless: chromium.headless || true,
      executablePath:
        (await chromium.executablePath) || '/bin/google-chrome-stable',
      args: chromium.args,
    });
    return await browser.newContext({
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1',
      viewport: { width: 808, height: 364 },
      screen: { width: 414, height: 896 },
      acceptDownloads: true,
      deviceScaleFactor: 3,
      isMobile: true,
      hasTouch: true,
    });
  };

You shoul use this function for every lambda.
Below, i show you an example about the aws-lambda declaration

# Basic
ValidateCredentials:
  handler: src/scrapper/validate-credentials/index.handler
  layers:
    - arn:aws:lambda:us-east-1:{id}:layer:crypto:1
    - arn:aws:lambda:us-east-1:{id}:layer:ws-layer:2 # This layer include chromium
    - arn:aws:lambda:us-east-1:{id}:layer:playwright:1 # This layer include playwright-core

@nwaguvictor
Copy link

nwaguvictor commented Aug 16, 2023 via email

@nwaguvictor
Copy link

nwaguvictor commented Aug 16, 2023 via email

@Facundojs
Copy link
Author

I cant se correctly the file. Looks like a github problem
Try copi/paste

@nwaguvictor
Copy link

nwaguvictor commented Aug 18, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants