Playwright do not find chromium on netlify

Hello,

After my ticket ENOENT problem only on netlify - #6 by hrishikesh I change of package for playwright and still have an issue. Playwright do not find chromium on netlify, or in local using netlify dev.

You can reproduce the issue doing this command :

curl --request POST \
  --url https://prismatic-cupcake-42f946.netlify.app/api/creation/eurl \
  --header 'Content-Type: application/json' \
  --data '{
	"revendicationEpoux": {
		"epoux": {
			"lastName": "obama",
			"address": "3 rue de la fantaisie",
			"city": "St jean de mont",
			"zipCode": "44000"
		},
		"fondateur": {
			"firstName": "barack",
			"lastName": "obama",
			"address": "3 rue de la fantaisie",
			"city": "St jean de mont",
			"zipCode": "44000",
			"share": 600
		},
		"company": {
			"address": "1 rue de washington",
			"city": "Nantes",
			"zipCode": "44000",
			"capital": 10000,
			"shareValue": 20,
			"name": "Obama Care"
		},
		"document": {
			"date": "2022-12-31"
		}
	}
}'

The error message will be

{
	"errorType": "Error",
	"errorMessage": "ENOENT: no such file or directory, open '/var/task/netlify/functions/creation/bin/chromium.br'",
	"trace": [
		"Error: ENOENT: no such file or directory, open '/var/task/netlify/functions/creation/bin/chromium.br'"
	]
}

If you give a gitlab account, I can give you access to the code to reproduce it locally using netlify dev command

The code work perfectly using jest with npm test

PS : I already test this solution but do not work for me GitHub - netlify-labs/netlify-functions-headless-chrome: Run headless chrome in Netlify functions

I try to install the playwright cache plugin too but it do not solve the problem

Have you downloaded Chromium? Does that exist in your repo? It would be really helpful if you can make it public.

Hello

I added you to the repo https://gitlab.com/easy-societe/pdf-generation
Follows thoses steps please

  1. git clone the repo
  2. enter the repo
  3. git checkout feat-document
  4. git pull
  5. mkdir output
  6. npm test
  7. see that pdfs are well generated in the output folder
  8. now do netlify dev
  9. you can hit the local endpoint with this javascript script
const data = JSON.stringify({
  "revendicationEpoux": {
    "epoux": {
      "lastName": "obama",
      "address": "3 rue de la fantaisie",
      "city": "St jean de mont",
      "zipCode": "44000"
    },
    "fondateur": {
      "firstName": "barack",
      "lastName": "obama",
      "address": "3 rue de la fantaisie",
      "city": "St jean de mont",
      "zipCode": "44000",
      "share": 600
    },
    "company": {
      "address": "1 rue de washington",
      "city": "Nantes",
      "zipCode": "44000",
      "capital": 10000,
      "shareValue": 20,
      "name": "Obama Care"
    },
    "document": {
      "date": "2022-12-31"
    }
  },
  "statut": {}
});

const xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "http://localhost:8888/api/creation/eurl");
xhr.setRequestHeader("Content-Type", "application/json");

xhr.send(data);

Or the remote netlify endpoint with steps describe above

I still can’t get your reproduction to work :slight_smile:

I get: TypeError: ES_Error2 is not a constructor

In any case, I can see that Playwright downloaded the browser binaries to:

/Users/<username>/Library/Caches/ms-playwright/chromium-1024

at least on macOS.

You need to download the Linux version of the binary and save it in your repo. Then, you can include it as explained here:

However, Chromium binary is over 100 MB in size and AWS supports Lambda only 50 MB zipped. There are high changes that this binary won’t fit in the size limits, but you’re free to try.