Skip to content

[πŸ› Bug]: [py] javascript_error_handler fails with Firefox due to stackTrace not present in the json objectΒ #14735

@qiu-lijie

Description

@qiu-lijie

What happened?

Trying to use the new BiDi feature to get browser console logs/errors with Firefox. However, with certain types (not sure the exact cause of this) of js error, a stackTrace object is not present in the json passed in callback handler, resulting in a KeyError and ws connection being closed, thus all subsequent logs/errors being lost

After some preliminary analysis, it seems like this line is causing the issue. Monkey patching it to stacktrace=json["stackTrace"] if "stackTrace" in json else {}, solved the issue for me, but I'm not sure what's causing these js errors with no stackTrace and if this issue exist with other browsers etc.

How can we reproduce the issue?

from selenium import webdriver

options = webdriver.FirefoxOptions()
options.enable_bidi = True
# somehow I need this for Firefox to work now, could be a separate issue
options.set_capability("loggingPrefs", None)
options.add_argument("--headless")
service = webdriver.FirefoxService(executable_path="/snap/bin/firefox.geckodriver")
driver = webdriver.Firefox(options=options, service=service)

console_logs = []
driver.script.add_console_message_handler(console_logs.append)
driver.script.add_javascript_error_handler(console_logs.append)

# example website with js error
driver.get('https://www.microsoft.com/en-ca/')
# observer error is not present
console_logs
# and subsequent get to the site result in no logs at all, neither js errors nor console logs

Relevant log output

N/A

Operating System

Ubuntu 24.04.1 (WSL and native)

Selenium version

Python 4.26.1

What are the browser(s) and version(s) where you see this issue?

Firefox 132.0.1 | 131.0.3

What are the browser driver(s) and version(s) where you see this issue?

geckodriver 0.35.0

Are you using Selenium Grid?

no

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!I-defectSomething is not working as intendedJ-staleApplied to issues that become stale, and eventually closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions