Here is my package.json
{
"scripts": {
"netlify": "netlify",
"serve": "netlify functions:serve",
"postinstall": "npx playwright install --with-deps"
},
"devDependencies": {
"netlify-cli": "^17.8.1"
},
"dependencies": {
"axios": "^1.6.2",
"playwright": "^1.44.1",
}
}
here is my netlify.toml
command = "./install-chromium-deps.sh && npm install && npm run build"
and here is the install-chromium-deps.sh:
#!/bin/bash
# Install dependencies for Playwright
apt-get install -y \
libevent-2.1-7 \
libopus0 \
libflite1 \
libevdev2 \
libgles2 \
gstreamer1.0-libav \
If I use " “postinstall”: “npx playwright install --with-deps” instead of “postinstall”: “npx playwright install” and comment out the Command in the .toml file
I get error:
1:45:44 PM: > postinstall
1:45:44 PM: > npx playwright install --with-deps
1:45:45 PM: Installing dependencies...
1:45:45 PM: Switching to root user to install dependencies...
1:45:46 PM: Failed during stage 'Install dependencies': dependency_installation script returned non-zero exit code: 1
1:45:46 PM: Password: su: Authentication failure
1:45:46 PM: Failed to install browsers
1:45:46 PM: Error: Installation process exited with code: 1
1:45:46 PM: npm ERR! code 1
1:45:46 PM: npm ERR! path /opt/build/repo
1:45:46 PM: npm ERR! command failed
1:45:46 PM: npm ERR! command sh -c -- npx playwright install --with-deps
1:45:46 PM: npm ERR! A complete log of this run can be found in:
1:45:46 PM: npm ERR! /opt/buildhome/.npm/_logs/2024-06-14T03_45_41_763Z-debug-0.log
1:45:46 PM: Error during npm install
1:45:46 PM: Failing build: Failed to install dependencies
If I use the Command and “postinstall”: “npx playwright install”, I get this error:
2:02:07 PM: Error message
2:02:07 PM: Command failed with exit code 127: ./install-chromium-deps.sh && npm install && npm run build
2:02:07 PM: ​
2:02:07 PM: Error location
2:02:07 PM: In build.command from netlify.toml:
2:02:07 PM: ./install-chromium-deps.sh && npm install && npm run build
2:02:07 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
How do I install Playwright browser dependencies correctly based on this?
if I don’t do this and use only playwright the code works fine locally but on Netlify I get this error I get this error:
browserType.launch: Executable doesn't exist at /home/sbx_user0000/.cache/ms-playwright/chromium-1117/chrome-linux/chrome Looks like Playwright Test or Playwright was just installed or updated. Please run the following command to download new browsers: npx playwright install
This is described here GitHub - nvh95/netlify-plugin-playwright-cache: 🤖 Persist the Playwright executable between Netlify builds however this plugin no longer works either.
@hrishikesh im using playwright inside the Netlify function not for tests just for taking page screenshots. The test cases in .yaml file are not good for me. The issue is well described here:
This plugin is out of date but the issue persist on Netlify. Locally everything works.
npx playwright install chromium
Installs to the cache location which is causing an issue.
Is there any other allowed way to install this package to a different location? I tried brew but also faced some issues.
I’d recommend using Puppeteer as if I recall, I was able to get that working in Functions. As already pointed out above, it’s not possible to install those dependencies on Netlify.
Hi @hrishikesh I changed the function to use Puppeteer however I’m facing a similar issue. Have a look here: https://api-functions.netlify.app/.netlify/functions/fetch-page-screenshoot-puppeteer?url=https://google.com
When I query this function, I get this error. Works fine on local:
{
"error": "Could not find Chrome (ver. 126.0.6478.126). This can occur if either\n 1. you did not perform an installation before running the script (e.g. `npx puppeteer browsers install chrome`) or\n 2. your cache path is incorrectly configured (which is: /home/sbx_user1051/.cache/puppeteer).\nFor (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration."
}
here is my netlify.toml
[build]
functions = "functions"
publish = "src"
command = "npx puppeteer browsers install chrome"
[[headers]]
for = "/*"
[headers.values]
Access-Control-Allow-Origin = "*"
@hrishikesh I also tried to amend the executablePath
to:
- /opt/buildhome/.cache/puppeteer/chrome/linux-126.0.6478.126/chrome-linux64/chrome
- /home/sbx_user1051/.cache/puppeteer
- /home/sbx_user1051/.cache/puppeteer/chrome
- /home/sbx_user1051/.cache/puppeteer/chrome/linux-126.0.6478.126/chrome-linux64/chrome
none of them succeed
{
"error": "Browser was not found at the configured executablePath (/opt/buildhome/.cache/puppeteer/chrome/linux-126.0.6478.126/chrome-linux64/chrome)"
}
Could you confirm, which executablePath
I should use. Thanks
Hi @hrishikesh I finally managed to make this work. Thank you for your help. The only disadvantage is that @sparticuz/chromium
is buggy. Does not work locally on MacOS and has little support. The suggested solution works for now. It will be great to have chromium out of the box on Netlify rather than using a third party. Thanks for your repo!
1 Like
Hi Netlify Team,
I’m generally very satisfied with your service, but I’m currently facing major issues setting up Playwright for our project on Netlify. The reliance on the Sparticuz/chromium plugin is problematic. It’s not well-maintained and doesn’t work on Unix systems locally.
Here’s the error we’re getting:
1:51:25 AM: Installing dependencies...
1:51:25 AM: Switching to root user to install dependencies...
1:51:26 AM: Failed during stage 'Install dependencies': dependency_installation script returned non-zero exit code: 1
1:51:26 AM: Password: su: Authentication failure
A better solution would be to grant su rights for deploy actions in the pipeline. This should be a simple fix that can be implemented in a day.
This issue is causing significant disruptions to our workflow. Please address it urgently, or we will need to consider switching to another hosting provider.
Disappointed,
Flame
I’ve already mentioned that you can use Playwright on a different system, linking the relevant post again: [Question] How to run playwright tests with a Netlify setup · Issue #9971 · microsoft/playwright · GitHub
As for:
I’m sure you’re right that this and can implement this within a day, but we won’t be doing it.
Dear Netlify Support Team and Hrishikesh ,
We are extremely disappointed with the customer service provided. Our use case involves more than just running end-to-end tests with Playwright; we need to integrate the actual Playwright instance within our code.
Despite spending half a day developing a GitHub webhook and action for Netlify to enable Chromium, we have not achieved success. Refactoring our feature into a serverless function for Netlify is not a feasible solution as it would be excessive for our needs.
Due to these limitations and the lack of adequate support, we have decided that if this issue is not resolved promptly, we will be compelled to switch all our customer-hosted projects to a different provider.
We hope for a swift and satisfactory resolution.
Best regard
I’m sorry, but I’m unsure what kind of a solution you’re expecting from Netlify here. Playwright requires certain system-level dependencies and we do not include those because that would lead to:
- A bigger build image size
- Slower builds for all Netlify users (as Build Image is the same used by all)
- Builds would also take more time to initialize to load the larger Build Image and boot into the bloated system
- More resource consumption by these services in the build means it would lead to lower available resources for the actual build process used by the users
With all these limitations, the solution is installing these dependencies manually by the user. We have no problem with that, by these depencies require root access which we’re not willing to provide. That would lead to a big chunk of security concerns.
Given the number of problems just to solve a very particular use-case does not work in our favour. If this makes you leave Netlify, I’m sorry for the disappointment you had from the service, but the above is not currently open for discussion.
1 Like
I understand the challenges, but as a major tech hosting provider like Netlify, I expect solutions to be offered. Software development and deployment are ongoing, dynamic processes, and there should be multiple solutions that don’t require root access. The Netlify pipeline should be capable of detecting the necessary dependencies for a Playwright/Chromium instance and smart enough to add an additional queue or action to provide this information. Ultimately, it’s just an instance that needs to be available.
Providing a way to easily integrate such dependencies would significantly enhance the user experience. This could be achieved through a more flexible build configuration, additional documentation, or pre-configured build images that can be opted into. It would be beneficial to address this in a manner that balances security, resource consumption, and user requirements.
While I understand the current limitations, exploring these options could prevent users from moving away from Netlify due to such specific needs.