diff --git a/lib/ferrum/browser.rb b/lib/ferrum/browser.rb index 9626ad1..ccf7b80 100644 --- a/lib/ferrum/browser.rb +++ b/lib/ferrum/browser.rb @@ -125,6 +125,9 @@ class Browser # @option options [Hash] :env # Environment variables you'd like to pass through to the process. # + # @option options [Boolean] :use_default_context + # When true, allows using the default browser context that has access to the browser's persistent state. + # def initialize(options = nil) @options = Options.new(options) @client = @process = @contexts = nil diff --git a/lib/ferrum/browser/options.rb b/lib/ferrum/browser/options.rb index 987f944..962cbe8 100644 --- a/lib/ferrum/browser/options.rb +++ b/lib/ferrum/browser/options.rb @@ -15,7 +15,7 @@ class Options :js_errors, :base_url, :slowmo, :pending_connection_errors, :url, :ws_url, :env, :process_timeout, :browser_name, :browser_path, :save_path, :proxy, :port, :host, :headless, :browser_options, - :ignore_default_browser_options, :xvfb, :flatten + :ignore_default_browser_options, :xvfb, :flatten, :use_default_context attr_accessor :timeout, :default_user_agent def initialize(options = nil) @@ -45,6 +45,7 @@ def initialize(options = nil) @base_url = parse_base_url(@options[:base_url]) if @options[:base_url] @url = @options[:url].to_s if @options[:url] @ws_url = @options[:ws_url].to_s if @options[:ws_url] + @use_default_context = @options.fetch(:use_default_context, false) @options = @options.merge(window_size: @window_size).freeze @browser_options = @options.fetch(:browser_options, {}).freeze diff --git a/lib/ferrum/contexts.rb b/lib/ferrum/contexts.rb index d6e28ea..a493ac4 100644 --- a/lib/ferrum/contexts.rb +++ b/lib/ferrum/contexts.rb @@ -11,7 +11,7 @@ class Contexts def initialize(client) @contexts = Concurrent::Map.new @client = client - @default_context = create_default_context + @default_context = create_default_context if @client.options.use_default_context subscribe auto_attach discover