0

I used to be able to run several instances of Chrome concurrently without issue. After a DevToolsTools active port file doesn't exist error popped up, the only solution that seemed to get things up and running was options.add_argument('--remote-debugging-port=9222'). However, since I have added that, I can no longer run concurrent or even sequential instances of the automated browser. Running the code below, I will get this error when browser2 tries to start:

(chrome not reachable) (The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

When I try to start a any browser instance with an existing one running I get the text:

Opening in existing browser session.

Chrome never tried to get into a existing session I added the options.add_argument('--remote-debugging-port=9222') I have tried an multitude of different solutions to the DevToolsTools active port file doesn't exist issue and this seemed to to be the only one that worked. I've also uninstalled and reinstalled chrome.

#selenium modules
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service as ChromiumService
#webdriver manager modules
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType
#utility modules
from random import randrange

def simple_chrome(page=""):
    options = Options()
    debugging_port = str(randrange(9222, 9999))
    options.add_argument('--remote-debugging-port=%s'%debugging_port)
    service = ChromiumService(ChromeDriverManager().install())
    browser = webdriver.Chrome(service=service, options=options)
    browser.get(page)
    return browser

browser = simple_chrome("https://docs.python.org/3/library/shutil.html")
browser2 = simple_chrome("https://apnews.com")
Jack
  • 89
  • 8
  • 1
    I would try opening the 2nd instance without setting the debug port. (that's usually used to attach to an IDE process/debugger that has already attached to/run Chrome so it'll tail on to that sessionID...) If you leave the option out, it'll, hopefully, assign it's own port and sessionID. – pcalkins Mar 21 '23 at 18:04
  • Thanks for reaching out. I just tried that suggestion. Running the second session without the debug port yielded the 'DevToolsActivePort file doesn't exist' error. – Jack Mar 21 '23 at 18:09
  • Sounds like something is preventing the browser from dropping the file that tells the driver what port and sessionID to use. Not sure what that might be... maybe try running Chrome from the user that runs this script. (manually, just to be sure Chrome sets up initial directories correctly...) Check permissions etc... Chrome is going to be creating temporary directories when launched in dev-mode (via chromedriver) – pcalkins Mar 21 '23 at 20:50
  • @pcalkins I've completely uninstalled and reinstalled Chrome a few times now. The profile and DevToolsActivePort file should exist in the [User Data](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md) directory. However, mine is being default saved to '%userprofile%\AppData\Local\Google\Chrome\d_xlincnu.' When I pass a '--user-data-dir=' argument, it opens a session with the same default directory and that session will yield the DevToolsActivePort file doesn't exist error. If I direct the default directory to d_xlincnu, it works but only in single instances. – Jack Mar 23 '23 at 18:37
  • I don't have a complete understanding of the mechanism but my work IT started managing chrome browsers. That's probably why it's always bypassing the User Data directory. So right now I'm looking to see if I can run chrome and my application in a venv. I just got to find a way to direct selenium to venv chrome instead of my default work chrome. – Jack Mar 23 '23 at 18:50
  • it's possible they changed things, but before I think the default behavior would be to create a temporary profile and a "scoped..." directory in '%userprofile%\AppData\Local\Temp folder. Which is where I believe the file would be created and then cleaned up along with the temporary profile when the driver is quit. Unsure of the behavior when setting it to use an existing profile. – pcalkins Mar 23 '23 at 19:14
  • I've just tried with a '--temp-profile' argument but when I check 'chrome://version/' it's still coming up with '%userprofile%\AppData\Local\Google\Chrome\d_xlincnu' for the profile path. I know it used to always set up my profiles in the Temp folder but it does not seem to do that anymore. At least not succesfully setting up the DevToolsActivePort file. – Jack Mar 23 '23 at 19:45

1 Answers1

1

I GOT IT!!! I've been working this on/off for a few months for a application that I barely use anymore. Thanks for the soundboard.

I had tried launching chrome with --user-data-dir= or --temp-profile per this thread. However, after some great suggestions, I noticed these options would always come up with the same weird profile path

%userprofile%\AppData\Local\Google\Chrome\d_xlincnu

which I checked by typing "chrome://version" in the browser address.

Chrome was always also coming up as 'managed' in the the browser settings. So I went to the registry editor and found some weird default profile in HKEY_LOCAL_MACHINE\Software\Policies\Google\Chrome. I deleted the profile and now it works!

I don't know how the bogus profile got there. Maybe I was trying some outlandish solution and put it in there and forgot.

Jack
  • 89
  • 8