I’m trying to make a Puppeteer script where Chrome remembers cookies even after I close and open it again. But it’s not working. The cookies disappear every time.
I’ve encountered this issue before, and it can be quite frustrating. One thing to check is if you’re properly closing the browser instance at the end of your script. If you’re using browser.close(), it might be wiping the user data. Try using browser.disconnect() instead.
Another potential solution is to explicitly save and load cookies. You can use the page.cookies() method to get the cookies, store them in a file, and then use page.setCookie() to restore them in your next session.
Lastly, ensure you have sufficient permissions for the userDataDir folder. Sometimes, Chrome can’t write to the directory due to permission issues, causing it to create a temporary profile instead.
hey, i had similar problem. try adding ‘–disable-extensions’ to ur args. also make sure ur not in incognito mode. sometimes antivirus can mess with chrome data too. good luck!
I’ve dealt with this exact issue in my Puppeteer projects. One thing that worked for me was setting ‘defaultViewport: null’ in the browserSettings. This lets Chrome use its default viewport size, which can sometimes help with cookie persistence.
Also, make sure you’re not accidentally clearing cookies in your script. I once spent hours debugging only to realize I had a stray page.evaluate(() => document.cookie = ‘’) hiding in my code.
If all else fails, you might want to try using a different browser instance like Firefox. In my experience, it’s sometimes more reliable with cookie handling in headless mode. Just remember to install puppeteer-firefox if you go that route.
Lastly, double-check your Chrome version. I’ve seen odd behavior with cookies in older versions, so updating might solve your problem.