简体   繁体   English

PuppeteerSharp正在隐身模式下打开2个镀铬窗口

[英]Puppeteer sharp is opening 2 chrome windows on incognito

I've just started using this port for puppeteer but I have a problem.我刚刚开始将此端口用于 puppeteer,但我遇到了问题。 When I put the flag "--incognito" or if I use the browser.CreateIncognitoBrowserContextAsync() I always get 2 chrome windows opened.当我放置标志“--incognito”或使用 browser.CreateIncognitoBrowserContextAsync() 时,我总是打开 2 个 chrome 窗口。 There is a fix for this issue ?有解决此问题的方法吗? If I do this to my chrome broswer using "--incognito" flag it will open only 1 instance.如果我使用“--incognito”标志对我的 chrome 浏览器执行此操作,它将仅打开 1 个实例。

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 
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM