Created
January 23, 2018 01:09
-
-
Save Ariex/6f425fbcab09e13d8bec39aba7c4a9b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Page = require('puppeteer/lib/Page'); | |
// the following 2 methods are originally from: https://github.com/GoogleChrome/puppeteer/issues/85#issuecomment-341743259, with some modification to fit puppeteerv1.0.0 | |
async function newPageWithNewContext(browser) { | |
const { browserContextId } = await browser._connection.send('Target.createBrowserContext'); | |
const { targetId } = await browser._connection.send('Target.createTarget', { url: 'about:blank', browserContextId }); | |
const target = await browser._targets.get(targetId); | |
const client = await browser._connection.createSession(targetId); | |
const page = await Page.create(client, target, browser._ignoreHTTPSErrors, browser._appMode, browser._screenshotTaskQueue); | |
page.browserContextId = browserContextId; | |
return page; | |
} | |
async function closePage(browser, page) { | |
if (page.browserContextId != undefined) { | |
await browser._connection.send('Target.disposeBrowserContext', { browserContextId: page.browserContextId }); | |
} | |
await page.close(); | |
} | |
module.exports = { | |
beginIncognito: async browser => { | |
let page = await newPageWithNewContext(browser); | |
page.endIncognito = async() => closePage(browser, page); | |
return page; | |
} | |
}; |
Thanks for this. However, I've noticed that the _targets
property isn't set in the browser object – at least not in the version from npm.
Thanks for the example. It seems that microsoft has changed their cookie names. MS0
has to be checked instead of MUID
in my case.
official API available since v1.5.0: browser.createIncognitoBrowserContext()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a test case. https://www.microsoft.com/en-au/ will create a cookie MUID for new visitors. So if incognito works, it should output 2 different MUID.
i got