Class: Selenium::WebDriver::BiDi::LogHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/webdriver/bidi/log_handler.rb

Constant Summary collapse

ConsoleLogEntry =
BiDi::Struct.new(:level, :text, :timestamp, :stack_trace, :type, :source, :method, :args)
JavaScriptLogEntry =
BiDi::Struct.new(:level, :text, :timestamp, :stack_trace, :type, :source)

Instance Method Summary collapse

Constructor Details

#initialize(bidi) ⇒ LogHandler

Returns a new instance of LogHandler.



27
28
29
30
# File 'lib/selenium/webdriver/bidi/log_handler.rb', line 27

def initialize(bidi)
  @bidi = bidi
  @log_entry_subscribed = false
end

Instance Method Details

#add_message_handler(type) ⇒ int

Returns id of the handler.

Returns:

  • (int)

    id of the handler



33
34
35
36
37
38
39
40
41
# File 'lib/selenium/webdriver/bidi/log_handler.rb', line 33

def add_message_handler(type)
  subscribe_log_entry unless @log_entry_subscribed
  @bidi.add_callback('log.entryAdded') do |params|
    if params['type'] == type
      log_entry_klass = type == 'console' ? ConsoleLogEntry : JavaScriptLogEntry
      yield(log_entry_klass.new(**params))
    end
  end
end

#remove_message_handler(id) ⇒ Object

Parameters:

  • id (int)

    of the handler previously added



44
45
46
47
# File 'lib/selenium/webdriver/bidi/log_handler.rb', line 44

def remove_message_handler(id)
  @bidi.remove_callback('log.entryAdded', id)
  unsubscribe_log_entry if @log_entry_subscribed && @bidi.callbacks['log.entryAdded'].empty?
end