Skip to content

Commit d851b23

Browse files
committed
Merge branch 'sloanesturz-sloane/quit'
2 parents 40c34ab + 3277b43 commit d851b23

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

.github/workflows/linter.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Linter
2-
on: [push]
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
37

48
jobs:
59
linters:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Added
44

55
- `Ferrum::Network#wait_for_idle!` raises an error if timeout reached.
6+
- `Ferrum::Browser#close` closes browser gracefully issuing a CDP command, doesn't clean up ruby resources.
67

78
### Changed
89

lib/ferrum/browser.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,22 @@ def quit
218218
@client = @process = @contexts = nil
219219
end
220220

221+
#
222+
# Crashes browser.
223+
#
221224
def crash
222225
command("Browser.crash")
223226
end
224227

228+
#
229+
# Close browser gracefully.
230+
#
231+
# You should clean up resources/connections in ruby world manually, it's only a CDP command.
232+
#
233+
def close
234+
command("Browser.close")
235+
end
236+
225237
#
226238
# Gets the version information from the browser.
227239
#

spec/browser_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,21 @@
329329
end
330330
end
331331

332+
describe "#close" do
333+
it "works after crash with explicit restart" do
334+
browser.go_to
335+
336+
expect { browser.close }.not_to raise_error
337+
sleep 2
338+
expect { browser.go_to }.to raise_error(Ferrum::DeadBrowserError)
339+
340+
browser.restart
341+
browser.go_to
342+
343+
expect(browser.body).to include("Hello world")
344+
end
345+
end
346+
332347
describe "#version" do
333348
it "returns browser version information" do
334349
version_info = browser.version

0 commit comments

Comments
 (0)