SeleniumHQ/selenium · error · Error::WebDriverError

#{message['error']}: #{message['message']} #{message['stackt

Error message

#{message['error']}: #{message['message']}
#{message['stacktrace']}

What it means

BiDi.send_cmd issues a WebDriver BiDi (bidirectional) websocket command and reads the response. If the browser's response hash contains an 'error' key, Selenium raises Error::WebDriverError with the error name, message, and JS stacktrace from the browser. It surfaces protocol-level failures of any BiDi command (script, network, browsingContext, etc.).

Source

Thrown at rb/lib/selenium/webdriver/bidi.rb:64

        @ws.callbacks
      end

      def add_callback(event, &block)
        @ws.add_callback(event, &block)
      end

      def remove_callback(event, id)
        @ws.remove_callback(event, id)
      end

      def session
        @session ||= Session.new(self)
      end

      def send_cmd(method, **params)
        data = {method: method, params: params.compact}
        message = @ws.send_cmd(**data)
        raise Error::WebDriverError, error_message(message) if message['error']

        message['result']
      end

      def error_message(message)
        "#{message['error']}: #{message['message']}\n#{message['stacktrace']}"
      end
    end # BiDi
  end # WebDriver
end # Selenium

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Read the embedded stacktrace and error token from the message to identify the exact BiDi method/param the browser rejected.
  2. Verify the browser version supports that BiDi command (check the W3C BiDi spec coverage for your browser).
  3. Align Selenium client and browser/driver versions.
  4. Validate command kwargs against the BiDi schema before calling send_cmd.
  5. If transient (browser restart), recreate the BiDi session and retry once.

Example fix

// before
bidi.send_cmd(:someCommand, params: x)
// after
begin
  bidi.send_cmd(:someCommand, params: x)
rescue Selenium::WebDriver::Error::WebDriverError => e
  warn "BiDi command failed: #{e.message}"
end
Defensive patterns

Strategy: try-catch

Try / catch

begin
  result = bidi.send_cmd(method_name, **params)
rescue Selenium::WebDriver::Error::WebDriverError => e
  # e.message contains 'error: ...\n<stacktrace>'
  raise unless e.message =~ /no such|invalid|unknown method/i
  # recover: log and degrade
end

Prevention

When it happens

Trigger: Any BiDi call — bidi.session, script calls, network intercept install, browsingContext commands — whose parameters the browser rejects, or a method unsupported by the running browser, returns a response with message['error'] set, tripping the raise in send_cmd.

Common situations: Calling a BiDi method not yet implemented in the installed browser version, malformed command params, browser crashed/restarted mid-session, Selenium client newer/older than browser BiDi support, enabling webSocketCapability: true against a grid that does not proxy BiDi.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/b2a969166967623a. Report an issue: GitHub.