-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[Question] Run headless Firefox with non-default executable path #4075
Comments
Hi, the |
Hi, is there any way that I can override this environment variable in the code? The Cloud Functions I am using doesn't have an option to specify an environment variable when running the script. |
// @ts-check
const playwright = require("playwright");
(async () => {
// needs to be before the launch of the browser.
process.env.PLAYWRIGHT_BROWSERS_PATH = "0";
const browser = await playwright.firefox.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('http://whatsmyuseragent.org/');
await page.screenshot({ path: `example.png` });
await browser.close();
})(); Something like that should work. |
I tried calling PLAYWRIGHT_BROWSERS_PATH=0 node theScript.js as you said and it worked perfectly. However, this |
Are you running it on Google Cloud Functions? |
I haven't tested on Google Cloud Functions yet, I am trying to test it on my local environment first. Do you have any suggestions for Playwright to work with GCF? All of what I am trying to do is to get it runs on GCF, and the problem with it is I can't execute something like this PLAYWRIGHT_BROWSERS_PATH=0 node foo.js on there. |
After some more research I found that you wrote a buildpack for Heroku. I think Firebase has a very similar issue with that, which involved the setting of environmental variables or that sort of things. |
Just make sure you have set the environment variable before you require the "playwright" module. |
Thanks @sunaram - that should do the trick! |
I followed the "Advanced Installation" guide and found a way to download the binaries browsers into the node_modules folder of my project instead of the default path.
However, when I run the script it returns an error:
I tried to modify the option 'executablePath' in the browserType.launch([options]) but got a similar error:
How could I specify the path of the executable for Playwright to run correctly?
*Note: the reason I want this specific behavior is I need to upload my functions to Firebase Cloud functions, which doesn't seem to run normally with the default path option (seems like it doesn't install the browsers when it npm install package.json). By attaching the browsers to the playwright folder in node_modules and upload the whole folder, I hope it could solve the problem.
The text was updated successfully, but these errors were encountered: