Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `Ferrum::Frame#frame_element` returns the element in which the window is embedded [#524]
- `Ferrum::Page#start_screencast` starts sending frames to record screencast [#494]
- `Ferrum::Page#stop_screencast` stops sending frames [#494]
- `Ferrum::Browser#new(incognito: false)` wether to create an incognito profile for the browser startup window, `true` by default.

### Changed

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ Ferrum::Browser.new(options)
```

* options `Hash`
* `:headless` (String | Boolean) - Set browser as headless or not, `true` by default.
* `:headless` (Boolean) - Set browser as headless or not, `true` by default.
* `:incognito` (Boolean) - Create an incognito profile for the browser startup window, `true` by default.
* `:xvfb` (Boolean) - Run browser in a virtual framebuffer, `false` by default.
* `:flatten` (Boolean) - Use one websocket connection to the browser and all the pages in flatten mode.
* `:window_size` (Array) - The dimensions of the browser window in which to
Expand Down
3 changes: 3 additions & 0 deletions lib/ferrum/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class Browser
# @option options [Boolean] :headless (true)
# Set browser as headless or not.
#
# @option options [Boolean] :incognito (true)
# Create an incognito profile for the browser startup window.
#
# @option options [Boolean] :xvfb (false)
# Run browser in a virtual framebuffer.
#
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 @@ -14,7 +14,7 @@ class Options
attr_reader :window_size, :logger, :ws_max_receive_size,
: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,
:save_path, :proxy, :port, :host, :headless, :incognito, :browser_options,
:ignore_default_browser_options, :xvfb, :flatten
attr_accessor :timeout, :default_user_agent

Expand All @@ -27,6 +27,7 @@ def initialize(options = nil)
@window_size = @options.fetch(:window_size, WINDOW_SIZE)
@js_errors = @options.fetch(:js_errors, false)
@headless = @options.fetch(:headless, true)
@incognito = @options.fetch(:incognito, true)
@flatten = @options.fetch(:flatten, true)
@pending_connection_errors = @options.fetch(:pending_connection_errors, true)
@process_timeout = @options.fetch(:process_timeout, PROCESS_TIMEOUT)
Expand Down
1 change: 1 addition & 0 deletions lib/ferrum/browser/options/chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def merge_required(flags, options, user_data_dir)
def merge_default(flags, options)
defaults = except("headless", "disable-gpu") if options.headless == false
defaults ||= DEFAULT_OPTIONS
defaults.delete("no-startup-window") if options.incognito == false
# On Windows, the --disable-gpu flag is a temporary workaround for a few bugs.
# See https://bugs.chromium.org/p/chromium/issues/detail?id=737678 for more information.
defaults = defaults.merge("disable-gpu" => nil) if Utils::Platform.windows?
Expand Down
1 change: 1 addition & 0 deletions lib/ferrum/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def add_target(params:, session_id: nil)
new_target = Target.new(@client, session_id, params)
# `put_if_absent` returns nil if added a new value or existing if there was one already
target = @targets.put_if_absent(new_target.id, new_target) || new_target
@default_target ||= target

new_pending = Concurrent::IVar.new
pending = @pendings.put_if_absent(target.id, new_pending) || new_pending
Expand Down
10 changes: 8 additions & 2 deletions lib/ferrum/contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,19 @@ def size

private

# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
def subscribe
@client.on("Target.attachedToTarget") do |params|
info, session_id = params.values_at("targetInfo", "sessionId")
next unless ALLOWED_TARGET_TYPES.include?(info["type"])

context_id = info["browserContextId"]
unless @contexts[context_id]
context = Context.new(@client, self, context_id)
@contexts[context_id] = context
@default_context ||= context
end

@contexts[context_id]&.add_target(session_id: session_id, params: info)
if params["waitingForDebugger"]
@client.session(session_id).command("Runtime.runIfWaitingForDebugger", async: true)
Expand Down Expand Up @@ -114,7 +120,7 @@ def subscribe
context&.delete_target(params["targetId"])
end
end
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity

def discover
@client.command("Target.setDiscoverTargets", discover: true)
Expand Down