SeleniumHQ/selenium · error · Error::WebDriverError
Don't know how to handle #{kind} events
Error message
Don't know how to handle #{kind} events What it means
HasLogEvents#on_log_event registers a listener for one of a fixed set of log event kinds (:console, :exception, :mutation). Passing any other kind raises Error::WebDriverError because there is no log_<kind>_events method to invoke. This is a Chromium/DevTools-backed feature.
Source
Thrown at rb/lib/selenium/webdriver/common/driver_extensions/has_log_events.rb:60
# @example Collect JavaScript exceptions
# exceptions = []
# driver.on_log_event(:exception) do |event|
# exceptions.push(event)
# end
#
# @example Collect DOM mutations
# mutations = []
# driver.on_log_event(:mutation) do |event|
# mutations.push(event)
# end
#
# @param [Symbol] kind :console, :exception or :mutation
# @param [#call] block which is called when event happens
# @yieldparam [DevTools::ConsoleEvent, DevTools::ExceptionEvent, DevTools::MutationEvent]
#
def on_log_event(kind, &block)
raise Error::WebDriverError, "Don't know how to handle #{kind} events" unless KINDS.include?(kind)
enabled = log_listeners[kind].any?
log_listeners[kind] << block
return if enabled
devtools.runtime.enable
__send__(:"log_#{kind}_events")
end
private
def log_listeners
@log_listeners ||= Hash.new { |listeners, kind| listeners[kind] = [] }
end
def log_console_events
devtools.runtime.on(:console_api_called) do |params|
event = DevTools::ConsoleEvent.new(View on GitHub (pinned to aa36b38e69)
Solutions
- Use one of :console, :exception, or :mutation.
- Pass a Symbol, not a String.
- For other event types, use the lower-level BiDi or DevTools APIs directly instead of on_log_event.
Example fix
// before
driver.on_log_event('console') { |e| ... }
driver.on_log_event(:network) { |e| ... }
// after
driver.on_log_event(:console) { |e| ... } Defensive patterns
Strategy: validation
Validate before calling
VALID_LOG_KINDS = %i[console exception mutation].freeze
raise ArgumentError, "unknown log kind #{kind}" unless VALID_LOG_KINDS.include?(kind.to_sym)
driver.on_log_event(kind.to_sym, &block) Type guard
def valid_log_kind?(kind) %i[console exception mutation].include?(kind.to_sym) end
Try / catch
begin driver.on_log_event(kind, &block) rescue Selenium::WebDriver::Error::WebDriverError => e raise unless e.message =~ /Don't know how to handle/ warn "use :console, :exception, or :mutation" end
Prevention
- Restrict kinds to :console, :exception, :mutation.
- Pass a Symbol, not a String.
- Use lower-level BiDi/DevTools APIs for event types on_log_event does not cover.
When it happens
Trigger: Calling driver.on_log_event(:network) { ... } or any kind not in KINDS = %i[console exception mutation].
Common situations: Typo in the kind symbol, expecting a kind that does not exist (e.g. :network, :error), passing a String instead of a Symbol, copying examples that assume more kinds than implemented.
Related errors
- Could not find a valid devtools version; use a more recent v
- Unknown pattern type: #{pattern_type}
- unknown driver: #{browser.inspect}
- detector must respond to #call
- CDP devtools module not loaded. Call import_devtools() first
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/86784fd018cd1648.
Report an issue: GitHub.