Class: Ferrum::Console
- Inherits:
-
Object
- Object
- Ferrum::Console
- Includes:
- Enumerable
- Defined in:
- lib/ferrum/console.rb,
lib/ferrum/console/message.rb,
lib/ferrum/console/location.rb,
sig/ferrum/console.rbs,
sig/ferrum/console/message.rbs,
sig/ferrum/console/location.rbs
Overview
Defined Under Namespace
Constant Summary collapse
- LIMIT =
1000
Instance Method Summary collapse
-
#clear ⇒ nil
Forgets the collected messages.
-
#each {|message, arg0| ... } ⇒ Enumerator, self
Yields each collected message, oldest first.
-
#empty? ⇒ Boolean
Whether no messages were collected.
-
#initialize(page) ⇒ Console
constructor
A new instance of Console.
-
#inspect ⇒ String
Debug representation of the console.
-
#last ⇒ Message?
The most recent message.
-
#off(id) ⇒ void
Removes a listener added via #on.
-
#on {|message, arg0| ... } ⇒ Integer
Calls the block for every new message.
-
#size ⇒ Integer
Number of collected messages.
-
#subscribe ⇒ void
private
Subscribes to the CDP events messages are built from.
-
#to_a ⇒ Array<Message>
The collected messages, oldest first.
Constructor Details
#initialize(page) ⇒ Console
Returns a new instance of Console.
22 23 24 25 26 27 28 |
# File 'lib/ferrum/console.rb', line 22 def initialize(page) @page = page @messages = [] @listeners = Concurrent::Map.new @listener_id = Concurrent::AtomicFixnum.new @mutex = Mutex.new end |
Instance Method Details
#clear ⇒ nil
Forgets the collected messages.
85 86 87 88 |
# File 'lib/ferrum/console.rb', line 85 def clear @mutex.synchronize { @messages.clear } nil end |
#each ⇒ self #each ⇒ ::Enumerator[Console::Message, self]
Yields each collected message, oldest first.
37 38 39 40 41 42 |
# File 'lib/ferrum/console.rb', line 37 def each(&) return to_enum(:each) { size } unless block_given? to_a.each(&) self end |
#empty? ⇒ Boolean
Whether no messages were collected.
76 77 78 |
# File 'lib/ferrum/console.rb', line 76 def empty? size.zero? end |
#inspect ⇒ String
Debug representation of the console.
139 140 141 |
# File 'lib/ferrum/console.rb', line 139 def inspect "#<#{self.class.name} size=#{size}>" end |
#last ⇒ Message?
The most recent message.
58 59 60 |
# File 'lib/ferrum/console.rb', line 58 def last @mutex.synchronize { @messages.last } end |
#off(id) ⇒ void
This method returns an undefined value.
Removes a listener added via #on.
109 110 111 |
# File 'lib/ferrum/console.rb', line 109 def off(id) @listeners.delete(id) end |
#on {|message, arg0| ... } ⇒ Integer
Calls the block for every new message. Prefer page.on(:console).
98 99 100 |
# File 'lib/ferrum/console.rb', line 98 def on(&block) @listener_id.increment.tap { |id| @listeners[id] = block } end |
#size ⇒ Integer
Number of collected messages.
67 68 69 |
# File 'lib/ferrum/console.rb', line 67 def size @mutex.synchronize { @messages.size } end |
#subscribe ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Subscribes to the CDP events messages are built from.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ferrum/console.rb', line 119 def subscribe @page.on("Runtime.consoleAPICalled") do |params| add(Message.from_console_api(params)) unless replayed?(params) end @page.on("Log.entryAdded") do |params| entry = params["entry"] add(Message.from_log_entry(entry)) unless entry["source"] == "worker" end @page.on("Runtime.exceptionThrown") do |params| add(Message.from_exception(params)) end end |
#to_a ⇒ Array<Message>
The collected messages, oldest first.
49 50 51 |
# File 'lib/ferrum/console.rb', line 49 def to_a @mutex.synchronize { @messages.dup } end |