2

To investigate Selenium test failures due to Javascript errors (in Google Chrome) I am running the tests locally (non-headless-ly) with the --auto-open-devtools-for-tabs command line option for Chrome in combination with the Debugger.setPauseOnExceptions Chrome Devtools Protocol command (see also Break on exception in Chrome using Selenium).

Apparently this does not work (any more), a small test case in Selenium for Python:

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver

options = webdriver.chrome.options.Options()

options.add_argument('--auto-open-devtools-for-tabs')

driver = webdriver.Chrome(
  options=options,
  service_args=["--verbose", "--log-path=chromedriver.log"]
)

wait = WebDriverWait(driver, 5)

page = """
<html>
   <head><title>Test</title></head>
   <body>
    <script>
      function errorTest() {
        setTimeout(() => alert('It should pause before me!'), 1000)
        throw new Error('Foobar')
      }
    </script>
    <button id="btn" onclick="errorTest()">Click me</button>
   </body>
</html>
"""

driver.get("data:text/html;charset=utf-8," + page)

wait.until(
  EC.title_contains("Test"),
  "Page did not load"
)

driver.execute_cdp_cmd("Debugger.enable", {})
driver.execute_cdp_cmd("Debugger.setPauseOnExceptions", {"state": "all"})

driver.find_element_by_id("btn").click()

According to chromedriver.log the CDP commands seem to be accepted properly. Is there something I missed?

Current (stable) Selenium client (3.141.0) on Python 3.8 and current Google Chrome (83).

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
phk
  • 2,002
  • 1
  • 29
  • 54
  • 1
    Could be a bug in Chrome. Try [bisecting](https://www.chromium.org/developers/bisect-builds-py) it. – wOxxOm Jun 26 '20 at 10:33
  • @wOxxOm Indeed was a bug (or rather a workaround for a bug which got fixed in the meantime). I reported it at http://crbug.com/1099671 and it was fixed in 86.0.4198.0 (currently in the Canary channel). – phk Jul 29 '20 at 07:23

0 Answers0