diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index a06cc17d..93912235 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,5 +1,9 @@ name: Linter -on: [push] +on: + push: + branches: + - main + pull_request: jobs: linters: diff --git a/CHANGELOG.md b/CHANGELOG.md index 901dd37c..b862db3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/ferrum/browser.rb b/lib/ferrum/browser.rb index 5f609a62..9626ad1d 100644 --- a/lib/ferrum/browser.rb +++ b/lib/ferrum/browser.rb @@ -218,10 +218,22 @@ def quit @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. # diff --git a/spec/browser_spec.rb b/spec/browser_spec.rb index bc91e563..da3b1f88 100644 --- a/spec/browser_spec.rb +++ b/spec/browser_spec.rb @@ -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