-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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] Google Cloud Function error (deploy) #2321
Comments
@MaiaVinicius Google Cloud Functions environment is missing the needed libraries for webkit. And IIRC there's no way to add missing dependencies to Google Cloud from the user land :( The only hope is to submit a feature request to google cloud and hope they'll fix them. If you end up filing this to Google, please post a link to the filed bug here for the future reference. |
Oh, wait!
@MaiaVinicius I see you try launching webkit, but your error log is mentioning
Is this log correct? |
Actually, I have tried all 3 drivers (chrome, firefox and webkit). All returned the same error. Thank you for the feedback. |
Got this issue as well, I'm assuming that either firebase doesn't run install scripts, or doesn't wait for it to finish (install script is async, but nothing's waiting for it AFAICT).
Although both of these are far from ideal 😿 |
@gluck 🤷♂️ we're not very familiar with firebase, unfortunately... I'll close this since it's unclear how we can help here. |
I'm getting this issue as well. Is it possible to add an option to bundle the browser being used as a part of the NPM package, instead of using the browser on-device? |
Hi @billfeng, since my comment the situation has improved (a bit) and you can use the package 'playwright-core' to avoid downloading the browsers and
Now that playwright has already tons of packaged ways ( |
Hi @gluck, thanks for the info, this is very helpful! I will try the method you described. Quick questions -
Also, I made some interesting hacky progress with a different method. By forcing Firebase cloud functions to install the browser binaries locally through running
I'm guessing playwright or the browser binary it installed needs this |
I'm currently using:
Without issues (I had issues when the major version was different). Pseudo code:
Your approach seems promising as well, not sure why the shared library is missing. |
This seems to work well now (I have only tested with playwright-chromium). Only initial issue was that the launch method did not find the executable: browserType.launch: Failed to launch chromium because executable doesn't exist at /root/.cache/ms-playwright/chromium-888113/chrome-linux/chrome Setting the environment variable PLAYWRIGHT_BROWSERS_PATH=0 resolved this, and I can now use playwright-chromium in Google Cloud Function to e.g. generate pdf 😃 Cheers BTW - had to raise memory limit to 1 GB to avoid running out of memory... |
For some reasons just using PLAYWRIGHT_BROWSERS_PATH=0 didn't work for me here. What worked for me when deploying Playwright to Google Cloud Function.
// tmp is folder where browser binary should be found, 1295 is browser version and it can change
const context = await browser.newContext({"executablePath": "tmp/firefox-1295/firefox/firefox"})
|
HI! Hm, ok. I set PLAYWRIGHT_BROWSERS_PATH for both build and runtime environment, e.g. for gcloud CLI: --set-build-env-vars="PLAYWRIGHT_BROWSERS_PATH=0" --set-env-vars="PLAYWRIGHT_BROWSERS_PATH=0" |
thanks for info, I'll double check it again and verify |
I can confirm that the above solution works well. Thank you for sharing this ! Here is a complete example that returns a screenshot of google when queried.
{
"dependencies": {
"chrome-aws-lambda": "10.1.0",
"playwright-core": "1.14.1"
}
}
const { chromium } = require('playwright-core');
const bundledChromium = require('chrome-aws-lambda');
module.exports.screenshot = async function (req, res) {
const url = "https://google.com/";
const browser = await Promise.resolve(bundledChromium.executablePath).then(
(executablePath) => {
if (!executablePath) {
// local execution
return chromium.launch({});
}
return chromium.launch({ executablePath });
}
);
const page = await browser.newPage();
await page.goto(url);
const screenshotBuffer = await page.screenshot({ fullPage: true });
await browser.close();
res.set("Content-Type", "image/png");
res.status(500).send(screenshotBuffer)
}; |
Could you also run this setup in the local firebase function emulator? Best, MM |
I've tried to do what @jdexyz suggested and got the following error when deploying to vercel
|
I had a similar issue with running playwright python. I was wondering why I could run from the command line but it was failing when running as a web user process. Turns out the path for browsers are stored in ~/.cache folder when running playwright install command For me the solution was to make sure that I ran playwright install command as the web user. |
Context:
Code Snippet
Describe the bug
I'm trying to deploy my playwright application in Google Cloud Functions. It seems like there is a problem to spawn the browser.
The text was updated successfully, but these errors were encountered: