Puppeteer sharp is opening 2 chrome windows on incognito

Viewed 845

I've just started using this port for puppeteer but I have a problem. When I put the flag "--incognito" or if I use the browser.CreateIncognitoBrowserContextAsync() I always get 2 chrome windows opened. There is a fix for this issue ? If I do this to my chrome broswer using "--incognito" flag it will open only 1 instance.

1 Answers

It's rather messy but this seems to work..

using (Browser browser = await Puppeteer.LaunchAsync(options))
{
     // create the async context 
    var context = await browser.CreateIncognitoBrowserContextAsync();

    // get the page created by default when launch async ran and close it whilst keeping the browser active
    var browserPages = await browser.PagesAsync();
    await browserPages[0].CloseAsync();

    // create a new page using the incognito context
    using (Page page = await context.NewPageAsync())
    {
        // do something 
    }
}
Related