Skip to content

Commit f0cec32

Browse files
authored
Merge pull request #116 from Nakilon/position
2 parents c356477 + 0486ca7 commit f0cec32

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ browser.go_to("https://github.com/")
234234
browser.stop
235235
```
236236

237+
#### position
238+
239+
Set the position for the browser window bounds
240+
241+
```ruby
242+
browser.position = { left: 10, top: 20 }
243+
browser.position # => [10, 20]
244+
```
237245

238246
## Finders
239247

lib/ferrum/browser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Browser
2626
frames frame_by main_frame
2727
evaluate evaluate_on evaluate_async execute evaluate_func
2828
add_script_tag add_style_tag bypass_csp
29-
on goto] => :page
29+
on goto position position=] => :page
3030
delegate %i[default_user_agent] => :process
3131

3232
attr_reader :client, :process, :contexts, :logger, :js_errors, :pending_connection_errors,

lib/ferrum/page.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ def resize(width: nil, height: nil, fullscreen: false)
108108
fitWindow: false)
109109
end
110110

111+
def position
112+
@browser.command("Browser.getWindowBounds", windowId: window_id).fetch("bounds").values_at("left", "top")
113+
end
114+
115+
def position=(left:, top:)
116+
@browser.command("Browser.setWindowBounds", windowId: window_id, bounds: { left: left, top: top })
117+
end
118+
111119
def refresh
112120
command("Page.reload", wait: timeout, slowmoable: true)
113121
end

spec/browser_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ module Ferrum
125125
end
126126
end
127127

128+
it "allows the window to be positioned" do
129+
expect(browser.position).to eq([0, 0])
130+
expect { browser.position = { left: 10, top: 20 } }.
131+
to change { browser.position }
132+
expect(browser.position).to eq([10, 20])
133+
end
134+
128135
it "allows the page to be scrolled" do
129136
browser.go_to("/ferrum/long_page")
130137
browser.resize(width: 10, height: 10)

0 commit comments

Comments
 (0)