Class: Lightpanda::Network
- Inherits:
-
Object
- Object
- Lightpanda::Network
- Defined in:
- lib/lightpanda/network.rb
Instance Attribute Summary collapse
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
Instance Method Summary collapse
- #clear ⇒ Object
- #disable ⇒ Object
- #enable ⇒ Object
-
#initialize(browser) ⇒ Network
constructor
A new instance of Network.
- #traffic ⇒ Object
-
#wait_for_idle(timeout: 5, connections: 0) ⇒ Object
rubocop:disable Naming/PredicateMethod.
Constructor Details
#initialize(browser) ⇒ Network
7 8 9 10 11 |
# File 'lib/lightpanda/network.rb', line 7 def initialize(browser) @browser = browser @traffic = [] @enabled = false end |
Instance Attribute Details
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
5 6 7 |
# File 'lib/lightpanda/network.rb', line 5 def browser @browser end |
Instance Method Details
#clear ⇒ Object
32 33 34 |
# File 'lib/lightpanda/network.rb', line 32 def clear @traffic.clear end |
#disable ⇒ Object
21 22 23 24 25 26 |
# File 'lib/lightpanda/network.rb', line 21 def disable return unless @enabled browser.command("Network.disable") @enabled = false end |
#enable ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/lightpanda/network.rb', line 13 def enable return if @enabled browser.command("Network.enable") subscribe @enabled = true end |
#traffic ⇒ Object
28 29 30 |
# File 'lib/lightpanda/network.rb', line 28 def traffic @traffic.dup end |
#wait_for_idle(timeout: 5, connections: 0) ⇒ Object
rubocop:disable Naming/PredicateMethod
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lightpanda/network.rb', line 36 def wait_for_idle(timeout: 5, connections: 0) # rubocop:disable Naming/PredicateMethod started_at = Time.now while Time.now - started_at < timeout pending = @traffic.count { |t| t[:response].nil? } return true if pending <= connections sleep 0.1 end false end |