How to launch Puppeteer Sharp with an already running chrome instance and an existing chrome profile?

178 views Asked by At

The C# code below only works if Chrome is NOT already running. My ultimate goal is to use a custom profile. I'm using .NET 7

browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
    ExecutablePath = @"C:\Program Files\Google\Chrome\Application\chrome.exe",
    UserDataDir    = @"C:\Users\Admin\AppData\Local\Google\Chrome\User Data",

    //Args         = new[] { "--profile-directory=Profile 3" },
    Headless       = true
});

I did some digging, this seems to be due to UserDataDir being locked if already used by a running Chrome instance.

PS. I'm also open to the possibility of using a portable Chrome install using a custom profile, I'm using the same code as above, but either Chrome is NOT launched or I get this exception:

Failed to launch browser!

0

There are 0 answers