Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce resize_windows option #425

Closed
Closed
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Ferrum::Browser.new(options)
* `:pending_connection_errors` (Boolean) - When main frame is still waiting for slow responses while timeout is
reached `PendingConnectionsError` is raised. It's better to figure out why you have slow responses and fix or
block them rather than turn this setting off. Default is true.
* `:resize_windows` (Boolean) - Determines whether windows are automatically set to the window_size. Default is true.
* `:browser_name` (Symbol) - `:chrome` by default, only experimental support
for `:firefox` for now.
* `:browser_path` (String) - Path to Chrome binary, you can also set ENV
Expand Down
3 changes: 3 additions & 0 deletions lib/ferrum/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class Browser
# why you have slow responses and fix or block them rather than turn this
# setting off.
#
# @option options [Boolean] :resize_windows (true)
# Whether browsers windows are automatically set to the window_size option.
#
# @option options [:chrome, :firefox] :browser_name (:chrome)
# Sets the browser's name. **Note:** only experimental support for
# `:firefox` for now.
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 @@ -16,7 +16,7 @@ class Options
:js_errors, :base_url, :slowmo, :pending_connection_errors,
:url, :env, :process_timeout, :browser_name, :browser_path,
:save_path, :extensions, :proxy, :port, :host, :headless,
:ignore_default_browser_options, :browser_options, :xvfb
:ignore_default_browser_options, :browser_options, :xvfb, :resize_windows

def initialize(options = nil)
@options = Hash(options&.dup)
Expand All @@ -27,6 +27,7 @@ def initialize(options = nil)
@js_errors = @options.fetch(:js_errors, false)
@headless = @options.fetch(:headless, HEADLESS)
@pending_connection_errors = @options.fetch(:pending_connection_errors, true)
@resize_windows = @options.fetch(:resize, true)
@process_timeout = @options.fetch(:process_timeout, PROCESS_TIMEOUT)
@browser_options = @options.fetch(:browser_options, {})
@slowmo = @options[:slowmo].to_f
Expand Down
6 changes: 4 additions & 2 deletions lib/ferrum/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,10 @@ def prepare_page

inject_extensions

width, height = @browser.window_size
resize(width: width, height: height)
if @browser.options.resize_windows
width, height = @browser.window_size
resize(width: width, height: height)
end

response = command("Page.getNavigationHistory")
transition_type = response.dig("entries", 0, "transitionType")
Expand Down
Loading