From 84da924984480e079aef60fa98fb1922af7d682d Mon Sep 17 00:00:00 2001 From: Ulysse Buonomo Date: Tue, 24 May 2022 19:29:49 +0200 Subject: [PATCH] Add `env` option --- README.md | 1 + lib/ferrum/browser/process.rb | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6310264e..964d552b 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ Ferrum::Browser.new(options) than this will cause a `Ferrum::DeadBrowserError`. * `:proxy` (Hash) - Specify proxy settings, [read more](https://github.com/rubycdp/ferrum#proxy) * `:save_path` (String) - Path to save attachments with [Content-Disposition](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) header. + * `:env` (Hash) - Environment variables you'd like to pass through to the process ## Navigation diff --git a/lib/ferrum/browser/process.rb b/lib/ferrum/browser/process.rb index 08704b20..f7e73cb1 100644 --- a/lib/ferrum/browser/process.rb +++ b/lib/ferrum/browser/process.rb @@ -73,6 +73,7 @@ def initialize(options) @logger = options[:logger] @process_timeout = options.fetch(:process_timeout, PROCESS_TIMEOUT) + @env = Hash(options[:env]) tmpdir = Dir.mktmpdir("ferrum_user_data_dir_") ObjectSpace.define_finalizer(self, self.class.directory_remover(tmpdir)) @@ -95,7 +96,8 @@ def start ObjectSpace.define_finalizer(self, self.class.process_killer(@xvfb.pid)) end - @pid = ::Process.spawn(Hash(@xvfb&.to_env), *@command.to_a, process_options) + env = Hash(@xvfb&.to_env).merge(@env) + @pid = ::Process.spawn(env, *@command.to_a, process_options) ObjectSpace.define_finalizer(self, self.class.process_killer(@pid)) parse_ws_url(read_io, @process_timeout)