Repository navigation
[rb] Allow to set environment variables when staring a browser - #17395
Conversation
Review Summary by QodoAllow setting environment variables when starting a browser
WalkthroughsDescription• Add ability to set environment variables when starting browser • Allow explicit env variable configuration via Service class • Pass env variables through ChildProcess to Process.spawn • Add comprehensive unit tests for env variable handling File Changes1. rb/lib/selenium/webdriver/common/child_process.rb
|
Code Review by Qodo
1.
|
There was a problem hiding this comment.
Pull request overview
Adds support in the Ruby bindings to pass an explicit environment hash into the driver service process launch, enabling callers to avoid inheriting (or to override) the Ruby process environment when starting a browser via its driver.
Changes:
- Add
envconfiguration toWebDriver::Serviceand propagate it throughServiceManagerintoChildProcess. - Update
ChildProcessto pass the env hash as the first argument toProcess.spawn. - Add unit tests covering env passing in
ChildProcess#startandChrome::Serviceinitialization.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| rb/lib/selenium/webdriver/common/service.rb | Introduces env attribute/keyword on the base Service configuration. |
| rb/lib/selenium/webdriver/common/service_manager.rb | Passes the configured env through to the spawned child process. |
| rb/lib/selenium/webdriver/common/child_process.rb | Uses Process.spawn(env, *command, options) to apply env overrides. |
| rb/spec/unit/selenium/webdriver/common/child_process_spec.rb | Adds specs asserting Process.spawn receives the env hash (and {} by default). |
| rb/spec/unit/selenium/webdriver/chrome/service_spec.rb | Adds a spec asserting Chrome::Service retains the provided env. |
3725918 to
51809ef
Compare
51809ef to
2e5da27
Compare
Currently, the environment variables used when launching a browser are the same as those of the Ruby process that performs the launch. However, there are times when want to change the environment variables passed to a browser. In our case, `LD_PRELOAD`. We want to set `LD_PRELOAD` to use jemalloc in Ruby, but we want to avoid setting it for Chrome because using jemalloc can cause crashes or unstable behavior. To address this issue, this PR fixes allow environment variables to be explicitly specified via the service.
2e5da27 to
4572e98
Compare
|
Nice @y-yagi! Before we merge, the new
Otherwise looks good to me! :) |
|
Persistent review updated to latest commit 2fbb347 |
Close Tempfile before spawning process to avoid EACCES on Windows. On Windows, an open file handle can prevent spawned processes from opening the same file for redirection, causing test failures.
|
Persistent review updated to latest commit 5ccc267 |
|
@aguspe |
|
Persistent review updated to latest commit c850774 |
JRuby environments may not have 'ruby' in PATH. Use RbConfig.ruby to get the path to the current Ruby interpreter instead.
|
Persistent review updated to latest commit adcba78 |
🔗 Related Issues
None
💥 What does this PR do?
Currently, the environment variables used when launching a browser are the same as those of the Ruby process that performs the launch.
However, there are times when want to change the environment variables passed to a browser. In our case,
LD_PRELOAD. We want to setLD_PRELOADto use jemalloc in Ruby, but we want to avoid setting it for Chrome because using jemalloc can cause crashes or unstable behavior.To address this issue, this PR fixes allow environment variables to be explicitly specified via the service.
🔧 Implementation Notes
🤖 AI assistance
💡 Additional Considerations
🔄 Types of changes