diff --git a/rb/lib/selenium/webdriver/common/driver.rb b/rb/lib/selenium/webdriver/common/driver.rb index c23fd5e22f81d..259d115d5c713 100644 --- a/rb/lib/selenium/webdriver/common/driver.rb +++ b/rb/lib/selenium/webdriver/common/driver.rb @@ -70,6 +70,7 @@ def for(browser, opts = {}) def initialize(bridge: nil, listener: nil, **opts) @service = nil + @devtools = nil bridge ||= create_bridge(**opts) add_extensions(bridge.browser) @bridge = listener ? Support::EventFiringBridge.new(bridge, listener) : bridge @@ -180,6 +181,7 @@ def quit bridge.quit ensure @service&.stop + @devtools&.close end # diff --git a/rb/lib/selenium/webdriver/devtools.rb b/rb/lib/selenium/webdriver/devtools.rb index 75006caefc3a8..d7d3721c5f1f8 100644 --- a/rb/lib/selenium/webdriver/devtools.rb +++ b/rb/lib/selenium/webdriver/devtools.rb @@ -20,6 +20,9 @@ module Selenium module WebDriver class DevTools + RESPONSE_WAIT_TIMEOUT = 30 + RESPONSE_WAIT_INTERVAL = 0.1 + autoload :ConsoleEvent, 'selenium/webdriver/devtools/console_event' autoload :ExceptionEvent, 'selenium/webdriver/devtools/exception_event' autoload :MutationEvent, 'selenium/webdriver/devtools/mutation_event' @@ -37,6 +40,10 @@ def initialize(url:) start_session end + def close + socket.close + end + def callbacks @callbacks ||= Hash.new { |callbacks, event| callbacks[event] = [] } end @@ -100,8 +107,8 @@ def attach_socket_listener next unless message['method'] callbacks[message['method']].each do |callback| - params = message['params'] # take in current thread! - Thread.new { callback.call(params) } + callback_thread = Thread.new(message['params'], &callback) + callback_thread.abort_on_exception = true end end end @@ -121,7 +128,7 @@ def incoming_frame end def wait - @wait ||= Wait.new(timeout: 10, interval: 0.1) + @wait ||= Wait.new(timeout: RESPONSE_WAIT_TIMEOUT, interval: RESPONSE_WAIT_INTERVAL) end def socket