playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[BUG] Does browserContext.addCookie only work with DEFAULT profile directory?

Open Gokulnath31 opened this issue 3 years ago • 2 comments

When I add cookies into the browserContext created by launchPersistentContext addCookies works only for profile with directory DEFAULT and not working for other profile directories

 let browserContext = await chromium.launchPersistentContext('user-data-dir', {
        headless: false,
        args: [
            "--timeout=100 * 1000",
            "--disable-site-isolation-trials",
            "--disable-web-security",
            "--disable-cross-origin",
            "--profile-directory=" + "DEFAULT"
        ],
        ignoreDefaultArgs: [
            "--headless",
            "--enable-automation",
            '--allow-running-insecure-content'
        ],
    });


    const jsonString = fs.readFileSync('auth.json');
    let auth = JSON.parse(jsonString);
    await browserContext.addCookies(auth.cookies) // works only if profile directory is DEFAULT
      
    let page = await browserContext.newPage();

Gokulnath31 avatar Sep 20 '22 06:09 Gokulnath31

Can you elaborate on your use case? Once you pass custom CLI args to the browsers, there is risk of things not working perfectly.

rwoll avatar Sep 20 '22 17:09 rwoll

@rwoll I am trying to use my gmail login cookies into the session .But I am unable to do that since addCookies not loading if profile directory is not DEFAULT.It should either work for all profile directories or shouldnt work at all. Its strange behaviour to work only for DEFAULT profile.

Gokulnath31 avatar Sep 21 '22 06:09 Gokulnath31

@Gokulnath31 The --profile-directory flag might not work perfectly with playwright API's right now. Sorry for the inconvenience!

aslushnikov avatar Sep 28 '22 09:09 aslushnikov