Skip to content

Commit

Permalink
feat: Add Ferrum::Browser#close
Browse files Browse the repository at this point in the history
  • Loading branch information
route committed Feb 25, 2024
1 parent e052e63 commit 3277b43
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Linter
on: [push]
on:
push:
branches:
- main
pull_request:

jobs:
linters:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Added

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

### Changed

Expand Down
17 changes: 12 additions & 5 deletions lib/ferrum/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,29 @@ def restart
def quit
return unless @client

begin
command('Browser.close')
rescue
end

contexts.close_connections

@client.close
@process.stop
@client = @process = @contexts = nil
end

#
# Crashes browser.
#
def crash
command("Browser.crash")
end

#
# Close browser gracefully.
#
# You should clean up resources/connections in ruby world manually, it's only a CDP command.
#
def close
command("Browser.close")
end

#
# Gets the version information from the browser.
#
Expand Down
15 changes: 15 additions & 0 deletions spec/browser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,21 @@
end
end

describe "#close" do
it "works after crash with explicit restart" do
browser.go_to

expect { browser.close }.not_to raise_error
sleep 2
expect { browser.go_to }.to raise_error(Ferrum::DeadBrowserError)

browser.restart
browser.go_to

expect(browser.body).to include("Hello world")
end
end

describe "#version" do
it "returns browser version information" do
version_info = browser.version
Expand Down

0 comments on commit 3277b43

Please sign in to comment.