SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.55k stars 8.16k forks source link

[🐛 Bug]: Regression in closed shadow root access with Chrome Beta 131 #14631

Open GaurangTandon opened 2 hours ago

GaurangTandon commented 2 hours ago

What happened?

Here's a video showing the issue: https://www.loom.com/share/1101be1e1c1a4770a439cf0041c5c882

Plain text output log for your convenience:

(venv) venv➜  test-selenium python runtest.py
Chrome 130.0.6723.59 (Official Build) (arm64)
Got exception while accessing inside closed shadow root
(venv) venv➜  test-selenium python runtest.py
Chrome 131.0.6778.3 (Official Build) beta (arm64)
Got text from inside closed shadow root inner text

Based on how Selenium has always behaved, I believe this new behavior on Chrome 131 is a regression. Running document.getElementById('root').shadowRoot still returns null in Chrome 131, so I think this might be a Selenium issue rather than Chrome issue. Please do let me know if it's otherwise and I will report it on bugs.chromium.org/p/chromedriver

How can we reproduce the issue?

Python code:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
options.add_argument("--disable-features=ChromeWhatsNewUI,PrivacySandboxSettings4")
options.add_argument("--disable-search-engine-choice-screen")
options.binary_location = '/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta'

driver = webdriver.Chrome(service=ChromeService(), options=options)

driver.get('chrome://version')
try:
  print('Chrome', driver.find_element(By.ID, 'version').text)
  driver.get('file:///Users/blazegt/test-selenium/test.html')
  root = driver.find_element(By.ID, 'root')
  shadow_root = root.shadow_root
  inner = shadow_root.find_element(By.ID, 'inner')
  print('Got text from inside closed shadow root', inner.text)
except:
  print('Got exception while accessing inside closed shadow root')

HTML file:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Shadow root</title>
</head>

<body>
    <div id="root"></div>
    <script>
        const shadow = root.attachShadow({ mode: 'closed', });
        const inner = document.createElement('inner');
        inner.id = 'inner';
        inner.textContent = 'inner text';
        shadow.appendChild(inner);
    </script>
</body>

</html>

Install selenium and run python runtest.py two times, once with the binary_location set to Chrome beta (as it is right now) and other without it (so it runs stable version). The video shows the step clearly.

Relevant log output

When I put

logger = logging.getLogger('selenium')
logger.setLevel(logging.DEBUG)

at the top of the Python file above, I don't get any logs output on the terminal.

Operating System

macOS

Selenium version

4.25.0

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

Chrome 131 beta

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

(automatically downloaded by Selenium)

Are you using Selenium Grid?

No response

github-actions[bot] commented 2 hours ago

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


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!