Skip to content

Commit

Permalink
feat: Implement Ferrum::Network#cache
Browse files Browse the repository at this point in the history
  • Loading branch information
route committed Jul 24, 2023
1 parent b231685 commit 43f0af2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions lib/ferrum/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions lib/ferrum/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 43f0af2

Please sign in to comment.