question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New session and cookies for each new page

See original GitHub issue

I am using headless chromium in incognito mode. I need to auth on a website with different account using one single browsers with separate pages simultaniously

async function newPageWithNewContext(browser) {
    const { browserContextId } = await browser._connection.send('Target.createBrowserContext');
    const { targetId } = await browser._connection.send('Target.createTarget', { url: 'about:blank', browserContextId });
    var targetInfo = { targetId: targetId }
    const client = await browser._connection.createSession(targetInfo);
    const page = await browser.newPage({ context: 'another-context' }, client, browser._ignoreHTTPSErrors, browser._screenshotTaskQueue);
    page.browserContextId = browserContextId;
    return page;
}

I use this function to create a new page

const page = await newPageWithNewContext(browser);

but pages still share cookies and sessions. How can I turn it off?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
abokizhcommented, Feb 12, 2021

Thank you! It worked!

1reaction
mrceperkacommented, Feb 12, 2021

@abokizh If you want to have independent/incognito page, you have to do following:

// 1.
const context = await browser.createIncognitoBrowserContext()
// 2.
const page = await context.newPage()

If you want another incognito page, you have to repeat these steps -> create another context

This way it works for me, hopefully it will work for you as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What are session cookies? Do they need consent? - CookieYes
Session cookies are cookies that last only for a single user session. Learn more about why they are used, if they need consent...
Read more >
Everything You Need to Know About Session Cookies - Securiti
A session cookie is a simple text file that a website installs on its visitor's device for temporary use. It helps track real-time...
Read more >
Develop a webpage for creating session and persistent ...
When a user visits a web page, his/her name can be stored in a cookie. ... 1) Session cookies 2) Persistent cookies ......
Read more >
Can I create a new session in another tab or window in ...
Chrome Incognito Mode gives you a new cookie jar, but cookies are shared across other incognito windows. At best, this means you can...
Read more >
What are Session Cookies? - AllAboutCookies.org
Webpages have no memories. A user going from page to page will be treated by the website as a completely new visitor. Session...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found