Skip to content

[πŸ› Bug]: Chrome extension windows are no longer included in window_handles - Remote debugging windowΒ #15685

@rookes

Description

@rookes

Description

When connecting to an existing session via remote debugging, Chrome extension windows are not included in driver.window_handles. This issue is new in the past few weeks, but I'm not sure exactly when it started.

To reproduce, open a chrome window with the option --remote-debugging-port=9222 , then run the code. The code prints out the title of every window in window_handles. Note that if there is any chrome extension tab open, it will not be included. I have tested this with multiple valid extensions, extension popups, and invalid extension URLs as well. All give the same result.

Example output with two tabs open: "chrome-extension://a" and the default "New Tab"
New Tab

Further, if the Chrome extension is the only tab open, then an error will be generated:

Traceback (most recent call last):
  File "C:\Users\username\Documents\test.py", line 8, in <module>
    driver = webdriver.Chrome(options=chrome_options)
  File "C:\Users\username\AppData\Roaming\Python\Python313\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__   
    super().__init__(
    ~~~~~~~~~~~~~~~~^
        browser_name=DesiredCapabilities.CHROME["browserName"],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        keep_alive=keep_alive,
        ^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\Users\username\AppData\Roaming\Python\Python313\site-packages\selenium\webdriver\chromium\webdriver.py", line 66, in __init__ 
    super().__init__(command_executor=executor, options=options)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python313\site-packages\selenium\webdriver\remote\webdriver.py", line 250, in __init__  
    self.start_session(capabilities)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python313\site-packages\selenium\webdriver\remote\webdriver.py", line 342, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python313\site-packages\selenium\webdriver\remote\webdriver.py", line 429, in execute   
    self.error_handler.check_response(response)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python313\site-packages\selenium\webdriver\remote\errorhandler.py", line 232, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open window in chrome
  (Session info: chrome=136.0.7103.49)
Stacktrace:
        GetHandleVerifier [0x00007FF73A60A145+76773]
        GetHandleVerifier [0x00007FF73A60A1A0+76864]
        (No symbol) [0x00007FF73A3C8F7A]
        (No symbol) [0x00007FF73A3A0A95]
        (No symbol) [0x00007FF73A4552BE]
        (No symbol) [0x00007FF73A454710]
        (No symbol) [0x00007FF73A447133]
        (No symbol) [0x00007FF73A4104D1]
        (No symbol) [0x00007FF73A411263]
        GetHandleVerifier [0x00007FF73A8CA8ED+2962317]
        GetHandleVerifier [0x00007FF73A8C4EC2+2939234]
        GetHandleVerifier [0x00007FF73A8E2FF3+3062419]
        GetHandleVerifier [0x00007FF73A624B9A+185914]
        GetHandleVerifier [0x00007FF73A62C78F+217647]
        GetHandleVerifier [0x00007FF73A612A44+111844]
        GetHandleVerifier [0x00007FF73A612BF2+112274]
        GetHandleVerifier [0x00007FF73A5F8A79+5401]
        BaseThreadInitThunk [0x00007FFE49BAE8D7+23]
        RtlUserThreadStart [0x00007FFE4AD114FC+44]

Reproducible Code

# Before running: 
#    1. open Chrome window with --remote-debugging-port=9222
#    2. open any tab with an extension url (starts with "chrome-extension://")
#       Note that the chrome-extension url does not need to be valid to replicate issue
#    3. Optionally, open some other normal tabs

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "localhost:9222") # connect to existing session
driver = webdriver.Chrome(options=chrome_options)

window_handles = driver.window_handles

for handle in window_handles:
    driver.switch_to.window(handle)
    print(driver.title)

Debugging Logs


What version of Selenium are you currently using?

4.31.0

The following statements are true

  • This applies to the most recent version of Selenium (we can't fix old versions)
  • This hasn't already been reported (I searched and didn't find it)
  • All information necessary to reproduce the issue has been provided above

Did this work for you before?

Yes this is a regression

If yes, what version of Selenium did it work with?

4.29.0

Operating System

Windows

Selenium Language Binding

Python

Which browsers are you experiencing the issue with?

Chrome

Are you using Selenium Grid?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions