Skip to content

[🐛 Bug]: Chrome extension windows are no longer included in window_handles - Remote debugging window #15685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
rookes opened this issue Apr 30, 2025 · 10 comments
Closed
3 tasks done
Labels
C-py Python Bindings D-chrome G-chromedriver Requires fixes in ChromeDriver I-defect Something is not working as intended OS-windows

Comments

@rookes
Copy link

rookes commented Apr 30, 2025

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

@rookes rookes added A-needs-triaging A Selenium member will evaluate this soon! I-defect Something is not working as intended labels Apr 30, 2025
@selenium-ci
Copy link
Member

@rookes, thank you for creating this issue. We will troubleshoot it as soon as we can.

Selenium Triage Team: remember to follow the Triage Guide

@github-actions github-actions bot added C-py Python Bindings D-chrome I-regression Something was working but we "fixed" it OS-windows labels Apr 30, 2025
@cgoldberg
Copy link
Contributor

Did this work for you before?
Yes this is a regression

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

Does it still work with selenium 4.29 and Chrome 136? Or were you using an older version of Chrome/ChromeDriver when it worked?

@cgoldberg cgoldberg added the J-awaiting answer Question asked of user; a reply moves it to triage again label Apr 30, 2025
@rookes
Copy link
Author

rookes commented Apr 30, 2025

Does it still work with selenium 4.29 and Chrome 136? Or were you using an older version of Chrome/ChromeDriver when it worked?

No, 4.29 has the same issues with 136, it seems to be due to a Chrome update. I was using an older version of chrome when it worked, 135.xx

@cgoldberg
Copy link
Contributor

cgoldberg commented Apr 30, 2025

So nothing has changed in the window handle code on the Selenium side, so this is a regression in either Chrome or Chromedriver.

@cgoldberg cgoldberg added G-chromedriver Requires fixes in ChromeDriver and removed J-awaiting answer Question asked of user; a reply moves it to triage again I-regression Something was working but we "fixed" it A-needs-triaging A Selenium member will evaluate this soon! labels Apr 30, 2025
@selenium-ci
Copy link
Member

Hi, @rookes.
This issue has been determined to require fixes in ChromeDriver.

You can see if the feature is passing in the Web Platform Tests.

If it is something new, please create an issue with the ChromeDriver team.
Feel free to comment the issues that you raise back in this issue. Thank you.

@slhck
Copy link
Contributor

slhck commented May 9, 2025

FWIW this has been reported here: https://groups.google.com/g/chromedriver-users/c/4367H-1kHwU

Since I haven't found any official bug report I created one here: https://issues.chromium.org/issues/416666972

@slhck
Copy link
Contributor

slhck commented May 9, 2025

Ahah, since ChromeDriver v136, a new enableExtensionTargets capability is required to be set:

let driver = await new Builder()
  .forBrowser("chrome")
  .setChromeOptions(
    new chrome.Options({
      'goog:chromeOptions': {
        'enableExtensionTargets': true,
      }
    })
    .addArguments([
      `load-extension=./test-extension`
    ])
    .setChromeBinaryPath(chromeBinary)
  )
  .setChromeService(new chrome.ServiceBuilder(chromeDriverBinary))
  .build();

See also the PSA by the ChromeDriver team and the example code here.

It seems to me that this should be documented somewhere in Selenium as well, just to make life easier for others running into this issue.

@rookes
Copy link
Author

rookes commented May 9, 2025

Thanks for looking into this, I'm glad it's an easy fix!

So does the error calling window_handles need to be addressed? When enableExtensionTargets is off and the only windows open are extension windows, there will be an error generated (see original post for example trace). It seems like ideally this call would just return an empty list or something like that. Is that something that needs to be handled on the ChromeDriver side too?

@mrchinhdev
Copy link

Ahah, since ChromeDriver v136, a new enableExtensionTargets capability is required to be set:

let driver = await new Builder()
.forBrowser("chrome")
.setChromeOptions(
new chrome.Options({
'goog:chromeOptions': {
'enableExtensionTargets': true,
}
})
.addArguments([
load-extension=./test-extension
])
.setChromeBinaryPath(chromeBinary)
)
.setChromeService(new chrome.ServiceBuilder(chromeDriverBinary))
.build();
See also the PSA by the ChromeDriver team and the example code here.

It seems to me that this should be documented somewhere in Selenium as well, just to make life easier for others running into this issue.

I had to log into my GitHub account to say that this works.
The code you need to use to correctly count the number of Chrome tabs is:

options.add_experimental_option('enableExtensionTargets', True)

@slhck
Copy link
Contributor

slhck commented May 12, 2025

So does the error calling window_handles need to be addressed? When enableExtensionTargets is off and the only windows open are extension windows, there will be an error generated (see original post for example trace). It seems like ideally this call would just return an empty list or something like that. Is that something that needs to be handled on the ChromeDriver side too?

I personally don't think Selenium should treat this in any specific way and instead continue raising the underlying ChromeDriver error. As a developer, that exception would have probably pointed me in the right direction, whereas an empty list would have certainly caused more confusion.

yorkxin added a commit to yorkxin/copy-as-markdown that referenced this issue May 29, 2025
Includes a hack to enable Selenium access to extension windows. See SeleniumHQ/selenium#15685
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-py Python Bindings D-chrome G-chromedriver Requires fixes in ChromeDriver I-defect Something is not working as intended OS-windows
Projects
None yet
Development

No branches or pull requests

5 participants