diff --git a/CHANGELOG.md b/CHANGELOG.md index 191c4025..422af0a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## [Unreleased](https://github.com/rubycdp/ferrum/compare/v0.13...main) ## ### Added +- `Ferrum::Network#cache(disable: true | false)` whether or not to use cache for every request - `Ferrum::Network::Exchange#xhr?` determines if the exchange is XHR - `Ferrum::Network::Request#xhr?` determines if the request is XHR - `Ferrum::Network::Response#loaded?` returns true if the response is fully loaded diff --git a/README.md b/README.md index 30472e4e..83f4c2b3 100644 --- a/README.md +++ b/README.md @@ -599,6 +599,14 @@ browser.network.offline_mode browser.go_to("https://github.com/") # => Ferrum::StatusError (Request to https://github.com/ failed(net::ERR_INTERNET_DISCONNECTED)) ``` +#### cache(disable: `Boolean`) + +Toggles ignoring cache for each request. If true, cache will not be used. + +```ruby +browser.network.cache(disable: true) +``` + ## Proxy You can set a proxy with a `:proxy` option: diff --git a/lib/ferrum/browser.rb b/lib/ferrum/browser.rb index 3b62fdf1..2564561b 100644 --- a/lib/ferrum/browser.rb +++ b/lib/ferrum/browser.rb @@ -237,11 +237,11 @@ def restart end def quit - if @client - @client.close - @process.stop - @client = @process = @contexts = nil - end + return unless @client + + @client.close + @process.stop + @client = @process = @contexts = nil end def resize(**options) diff --git a/lib/ferrum/network.rb b/lib/ferrum/network.rb index 5405e256..860c886d 100644 --- a/lib/ferrum/network.rb +++ b/lib/ferrum/network.rb @@ -340,6 +340,16 @@ def offline_mode emulate_network_conditions(offline: true, latency: 0, download_throughput: 0, upload_throughput: 0) end + # + # Toggles ignoring cache for each request. If true, cache will not be used. + # + # @example + # browser.network.cache(disable: true) + # + def cache(disable:) + @page.command("Network.setCacheDisabled", cacheDisabled: disable) + end + private def subscribe_request_will_be_sent