Chrome Developer Tools closes instantly when attempting to debug WebDriver E2E test
debugging, google-chrome-devtools, selenium, webdriver
Solution
Chrome isn't doing this; ChromeDriver 2 is. ChromeDriver 2 and the DevTools windows both compete for the same automation channel, and ChromeDriver automatically closes the DevTools window in order for it to work.
See https://sites.google.com/a/chromium.org/chromedriver/help/devtools-window-keeps-closing for more info
Also see the related issue: https://code.google.com/p/chromedriver/issues/detail?id=483
Problem
I usually debug my Selenium tests in Chrome's dev tools panel. However, after upgrading my OS (Ubuntu Linux), my E2E tests broke completely: Chrome didn't open the first page, but sat idle showing only a blank page. Eventually I upgraded ChromeDriver, and now the tests work again. But with this new Chrome version (after the OS upgrade) and with this new ChromeDriver, there's a weird problem with the dev tools window: Whenever I click CTRL + SHIFT + I to open the dev tools window, or click Tools -> Developer Tools in Chrome's menu, the dev tools window flashes open, but then closes instantly. It looks blank and empty, the 1/10 seconds it's visible. This has really never happened before. When I manually open another tab in [the Chrome instance that's being driven by WebDriver], and navigate to e.g. http://www.google.se/, then, when I open the dev tools window in that tab, it usually stays open (but not always). — It's mainly [the dev tools window for the browser tab that is being controlled by the Chrome Driver] that closes instantly. However if I hold town CTRL+SHIFT+I for a while, this genereates many many "clicks", and then the dev tools suddenly stays open, sometimes. But after 10-20 seconds it suddenly closes again. Why is Chrome doing this? How can I have it stop? Chrome Version 29.0.1547.57 Chrome Driver versions 2.0, 2.1 and 2.2 tested (and problem present). Selenium 2.35.0, and version 2.25.0 (I think it was) also didn't work.