How do I establish an open connection to an open web browser in C#?
In a Microsoft C# program using a Visual Studio Code I am using the following namespaces:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
After I get a string variable, "url", assigned with a URL of a website page, I use the following commands which successfully opens a browser window and loads the web site:
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl(url);
But this opens a chrome browser which is denoted somewhere as being a "test" session. It somehow knows it was launched from a program. And, since I am using this program to automate some interactions with linkedin, this information is passed along to linkedin which prompts me that it requires I login. This creates a cascading seriies of events that are difficult to automate including using my cell as a means of verification.
So, instead of taking this route, how do I establish an open connection to an open web browser in C#? I figure, if I instead connect to a web browser that is already open and already has its veriication steps done with linkedin, then I won't be prompted to log in and do any user verification.

Jayraj ChhayaPosted Dec 26, 2024, 6:05 AM
Hi William Thompson,
To connect to an already open instance of a web browser using C#, you can utilize the Chrome DevTools Protocol (CDP) with Selenium. This approach allows you to attach to an existing Chrome session rather than launching a new one. Here’s how you can achieve this:
Start Chrome with Remote Debugging: First, you need to start Chrome with the
--remote-debugging-portoption. You can do this by running the following command in your terminal:By following these steps, you can interact with the already authenticated session of LinkedIn without being prompted to log in again. This method effectively circumvents the need for additional verification steps, streamlining your automation process.