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
[feat] Allow environment variables definition when launching chromium #912
[feat] Allow environment variables definition when launching chromium #912
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
fb9e59b
to
8f00c4e
Compare
Hi @BenoitZugmeyer, thank you for the pull request. The code looks legit. However, I wonder if setting up const savedEnv = Object.assign({}, process.env);
process.env.TZ = 'America/Noronha';
const browser = await puppeteer.launch();
Object.assign(process.env, savedEnv); // Restore env |
It is indeed possible to mutate the const savedEnv = Object.assign({}, process.env);
process.env.TZ = 'America/Noronha';
const browserPromise = puppeteer.launch();
Object.assign(process.env, savedEnv); // Restore env
const browser = await browserPromise; This is possible because Also, in my opinion, documenting the possibility to define the chromium environment variables this way is clearer than letting the user guess how to do it by mutating |
test/test.js
Outdated
// Disabled on Windows until we find a good use case on this platform. The | ||
// TZ environment variable is currently ignored, see | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=125614 | ||
(process.platform === 'win32' ? xit : it)('env option', SX(async function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets not add this test - it adds more debt.
The patch is small and mostly does plumbing, so we can tolerate landing this without a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, test removed! (commit amended)
8f00c4e
to
2b65e1f
Compare
Why setting the time zone to "Asia/Shanghai" does not work, and eventually I use 'utc-8' instead? |
I'd like to launch Chromium with a specific timezone for my tests. On Linux and macOS, I just need to define the
TZ
environment variable to the wanted timezone. So I added a newpuppeteer.launch()
option to allow defining the environment variables of the forked process.I read the contributing rules, but I failed to write a good unit test for Windows, because Chromium seems to ignore the TZ environment variable on this platform. If anyone have an idea for a more cross-platform unit test, I'd be happy to amend my PR. For now, the test is simply disabled on Windows.
FWIW, a similar issue is open at the chrome-launcher project.