Skip to content

Commit

Permalink
fix: #203 window-size is for window, page can have its own resolution…
Browse files Browse the repository at this point in the history
… and viewport (#427)
  • Loading branch information
route authored Dec 21, 2023
1 parent b8b0128 commit 447165b
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 20 deletions.
11 changes: 2 additions & 9 deletions lib/ferrum/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class Browser
add_script_tag add_style_tag bypass_csp
on position position=
playback_rate playback_rate=
disable_javascript set_viewport] => :page
disable_javascript set_viewport resize] => :page
delegate %i[default_user_agent] => :process

attr_reader :client, :process, :contexts, :options, :window_size, :base_url
attr_reader :client, :process, :contexts, :options, :base_url
attr_accessor :timeout

#
Expand Down Expand Up @@ -126,7 +126,6 @@ def initialize(options = nil)
@client = @process = @contexts = nil

@timeout = @options.timeout
@window_size = @options.window_size
@base_url = @options.base_url if @options.base_url

start
Expand Down Expand Up @@ -228,7 +227,6 @@ def command(*args)
# browser.quit
#
def reset
@window_size = options.window_size
contexts.reset
end

Expand All @@ -245,11 +243,6 @@ def quit
@client = @process = @contexts = nil
end

def resize(**options)
@window_size = [options[:width], options[:height]]
page.resize(**options)
end

def crash
command("Browser.crash")
end
Expand Down
1 change: 0 additions & 1 deletion lib/ferrum/browser/options/chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class Chrome < Base
def merge_required(flags, options, user_data_dir)
flags = flags.merge("remote-debugging-port" => options.port,
"remote-debugging-address" => options.host,
# Doesn't work on MacOS, so we need to set it by CDP
"window-size" => options.window_size&.join(","),
"user-data-dir" => user_data_dir)

Expand Down
3 changes: 0 additions & 3 deletions lib/ferrum/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,6 @@ def prepare_page

inject_extensions

width, height = @browser.window_size
resize(width: width, height: height)

response = command("Page.getNavigationHistory")
transition_type = response.dig("entries", 0, "transitionType")
return if transition_type == "auto_toplevel"
Expand Down
7 changes: 0 additions & 7 deletions spec/browser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,6 @@
expect(browser.viewport_size).to eq([200, 400])
end

it "inherits size for a new window" do
browser.go_to
browser.resize(width: 1200, height: 800)
page = browser.create_page
expect(page.viewport_size).to eq [1200, 800]
end

it "resizes windows" do
browser.go_to

Expand Down

0 comments on commit 447165b

Please sign in to comment.