I am attempting to have Playwright connect to an existing Chrome instance that is already open, so that I can avoid logging in each time. I have tried numerous times to use StorageState or SetCookies, and they simply do not work, so I have given up on that.
Unfortunately, I cannot seem to ever get it to connect. It simply times out, and says little more.
Variations I've tried, all resulting in timeout, though the error insinuating it connected before disconnecting...:
_browser = await _playwright.Chromium.ConnectOverCDPAsync("ws://127.0.0.1:9222/devtools/browser/aec930b5-bd2b-4e6c-8b00-68f0a414ad77");
_browser = await _playwright.Chromium.ConnectOverCDPAsync("http://localhost:9222");
The following just opens a new incognito window, instead of using the same existing session, thus requiring log in:
_browser = await _playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
ExecutablePath = @"C:\Program Files\Google\Chrome\Application\chrome.exe",
});
I also ensure I restart the browser, after killing all Chrome instances, with remote debugging enabled. I even tried administrator mode for giggles as well, to no avail.
"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
I have confirmed that Chrome DevTools Protocol (CDP) is enabled by going to:
http://127.0.0.1:9222/json/version
Which displays:
{
"Browser": "Chrome/122.0.6261.112",
"Protocol-Version": "1.3",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
"V8-Version": "12.2.281.21",
"WebKit-Version": "537.36 (@9d4c1072da62b411b351a38b9ed6214ab236aa7b)",
"webSocketDebuggerUrl": "ws://127.0.0.1:9222/devtools/browser/aec930b5-bd2b-4e6c-8b00-68f0a414ad77"
}
So it sure looks like it should be able to connect via CDP, but times out regardless.
Opening a new instance of Chrome or Firefox with custom profile that is already logged in would be a suitable solution as well. So far all I can get working is the conventional, open an "incognito" style browser.
Unfortunately logging in cannot be skipped in this funky situation, so no need to suggest that!
I would appreciate any guidance y'all can provide.
Many a times 9222 port does not work try a different number like 9214,9234 etc
first of all goto chrome location installation via cd
run the below command to start the browse on the port might not be 9222 as i also sometimes faced the issue of not opening
once the browser is opened you can login et and do the prereqisite
The below code should help in connecting to that already opened browser
I have been using this. Only problem is port sometimes rest all works