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

steep:ignore:start

Returns:

  • (int)

    id of the handler



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

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



46
47
48
49
# File 'lib/selenium/webdriver/bidi/log_handler.rb', line 46

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