File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,7 @@ Ferrum::Browser.new(options)
183183 than this will cause a ` Ferrum::DeadBrowserError ` .
184184 * ` :proxy ` (Hash) - Specify proxy settings, [ read more] ( https://github.com/rubycdp/ferrum#proxy )
185185 * ` :save_path ` (String) - Path to save attachments with [ Content-Disposition] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition ) header.
186+ * ` :env ` (Hash) - Environment variables you'd like to pass through to the process
186187
187188
188189## Navigation
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ def initialize(options)
7373
7474 @logger = options [ :logger ]
7575 @process_timeout = options . fetch ( :process_timeout , PROCESS_TIMEOUT )
76+ @env = Hash ( options [ :env ] )
7677
7778 tmpdir = Dir . mktmpdir ( "ferrum_user_data_dir_" )
7879 ObjectSpace . define_finalizer ( self , self . class . directory_remover ( tmpdir ) )
@@ -95,7 +96,8 @@ def start
9596 ObjectSpace . define_finalizer ( self , self . class . process_killer ( @xvfb . pid ) )
9697 end
9798
98- @pid = ::Process . spawn ( Hash ( @xvfb &.to_env ) , *@command . to_a , process_options )
99+ env = Hash ( @xvfb &.to_env ) . merge ( @env )
100+ @pid = ::Process . spawn ( env , *@command . to_a , process_options )
99101 ObjectSpace . define_finalizer ( self , self . class . process_killer ( @pid ) )
100102
101103 parse_ws_url ( read_io , @process_timeout )
Original file line number Diff line number Diff line change @@ -21,6 +21,22 @@ class Browser
2121 subject . quit
2222 end
2323 end
24+
25+ context "env variables" do
26+ subject { Browser . new ( env : { "LD_PRELOAD" => "some.so" } ) }
27+
28+ it "passes through env" do
29+ allow ( ::Process ) . to receive ( :wait ) . and_return ( nil )
30+ allow ( Client ) . to receive ( :new ) . and_return ( double . as_null_object )
31+
32+ allow ( ::Process ) . to receive ( :spawn ) . with ( { "LD_PRELOAD" => "some.so" } , any_args )
33+
34+ allow_any_instance_of ( Process ) . to receive ( :parse_ws_url )
35+
36+ subject . send ( :start )
37+ subject . quit
38+ end
39+ end
2440 end
2541 end
2642end
You can’t perform that action at this time.
0 commit comments