123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Inherits: Object
Defined in: rb/lib/selenium/webdriver/bidi/log_handler.rb

Constant Summary

Class Method Summary

Instance Method Summary

Constructor Details

.new(bidi) ⇒ LogHandler

[ GitHub ]

  
# File 'rb/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:

  • (int)

    id of the handler

[ GitHub ]

  
# File 'rb/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)

Parameters:

  • id (int)

    of the handler previously added

[ GitHub ]

  
# File 'rb/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

#subscribe_log_entry (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/log_handler.rb', line 51

def subscribe_log_entry
  @bidi.session.subscribe('log.entryAdded')
  @log_entry_subscribed = true
end

#unsubscribe_log_entry (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/bidi/log_handler.rb', line 56

def unsubscribe_log_entry
  @bidi.session.unsubscribe('log.entryAdded')
  @log_entry_subscribed = false
end