Skip to content

Commit

Permalink
Add option to allow using the browser's default context
Browse files Browse the repository at this point in the history
This would grant access to persistent state such as cookies that are
associated with the default browser profile.
  • Loading branch information
ibrahima committed Jul 4, 2024
1 parent 556ccad commit f24136d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/ferrum/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/ferrum/browser/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/ferrum/contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f24136d

Please sign in to comment.