florentbr / SeleniumBasic

A Selenium based browser automation framework for VB.Net, VBA and VBScript
BSD 3-Clause "New" or "Revised" License
421 stars 197 forks source link

I can no longer attach to an Existing Instance of Chrome since Chrome was updated to 114.0.5735.199 (Official Build) (64-bit) (cohort: Stable) in Late June #267

Open HenryJamesWas opened 1 year ago

HenryJamesWas commented 1 year ago

The below code from your examples spreadsheet Module1.browsers_debug used to work.

Since Chrome was updated (and chromedriver was updated) in late June it no longers works. I have confirmed this on two different machines. I get the following error VBA error:

UnknownError
unknown error: cannot connect to chrome at localhost:9222
from chrome not reachable
  (Driver info: chromedriver=114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}),platform=Windows NT 10.0.17134 x86_64)
Private Sub Connect_To_Chrome()
  'Use this command line to launch the browser:
  'chrome.exe -remote-debugging-port=9222

  Dim driver As New ChromeDriver
  driver.SetCapability "debuggerAddress", "127.0.0.1:9222"
  driver.Get "https://en.wikipedia.org"
  driver.Quit
End Sub
GCuser99 commented 1 year ago

The below code works for me (Chrome version 114.0.5735.199 (64 bit), Windows 11, Chrome Driver version 114.0.5735.90).

Private Sub Connect_To_Chrome()
    'start the browser on the debugging port
    CreateObject("WScript.Shell").Run "chrome.exe --remote-debugging-port=9222"

    Dim driver As New ChromeDriver
    driver.SetCapability "debuggerAddress", "127.0.0.1:9222"
    driver.Get "https://en.wikipedia.org"
    driver.Quit
End Sub
HenryJamesWas commented 1 year ago

Thanks for responding, GCuser99. I get the same error trying to run the above code, but the fact that it works for you is useful information. Maybe it has something to do with my browser configuration.

GCuser99 commented 1 year ago

@HenryJamesWas, did you update to the latest ChromeDriver?

HenryJamesWas commented 1 year ago

Yes, I did. The chromedriver otherwise seems to be working. I just cannot attach to the existing manually started Chrome session. Do you know, by any chance, what should happen if type "127.0.0.1:9222" in the chrome address bar? I get a "connection refused" message. I wonder if this is related.

GCuser99 commented 1 year ago

I do not get a "connection refused". Do you have any other Chrome browser instances open? Manually close any other Chrome browser windows and then try this:

Private Sub Connect_To_Chrome()
    Dim wshell As Object

    Set wshell = CreateObject("WScript.Shell")

    'first kill chrome processes
    wshell.Run "taskkill /f /t /im chrome.exe", 0, True
    'start the browser on the debugging port
    wshell.Run "chrome.exe --remote-debugging-port=9222"

    Dim driver As New ChromeDriver
    driver.SetCapability "debuggerAddress", "localhost:9222"
    driver.Get "http://localhost:9222/json"
    driver.Quit
End Sub
GCuser99 commented 1 year ago

@HenryJamesWas, curious if you ever figured this one out?

HenryJamesWas commented 1 year ago

Hi, GCuser99. I just tried your code. It loaded the json file. I am now able to attach to that session of chrome. To my knowledge, I didn't have other browsers instances open before. In any event, I can now connect to the browser. Your suggestion of running the taskkill command prior to launching chrome in debugging mode appears to have solved my problem! Thanks!