     [Answers](https://scrapfly.io/blog)   /  [headless-browser](https://scrapfly.io/blog/tag/headless-browser)   /  [How to save and load cookies in Puppeteer?](https://scrapfly.io/blog/answers/how-to-save-and-load-cookies-in-puppeteer)   # How to save and load cookies in Puppeteer?

 by [Bernardas Alisauskas](https://scrapfly.io/blog/author/bernardas) Oct 28, 2022 1 min read [\#headless-browser](https://scrapfly.io/blog/tag/headless-browser) [\#puppeteer](https://scrapfly.io/blog/tag/puppeteer) 

 [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-save-and-load-cookies-in-puppeteer "Share on LinkedIn")    

 

 

When web scraping, we often need to save the connection state like browser cookies and resume it later. Using Puppeteer, to save and load cookies we can use `page.cookies()` and `page.setCookie()` methods:

javascript```javascript
const puppeteer = require('puppeteer');
const fs = require('fs').promises;

async function run() {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();

    // get some cookies:
    await page.goto("https://httpbin.dev/cookies/set/mycookie/myvalue");
    // then we can save them as JSON file:
    const cookies = await page.cookies();
    await fs.writeFile('cookies.json', JSON.stringify(cookies));

    // then later, we load the cookies from file:
    const cookies = JSON.parse(await fs.readFile('./cookies.json'));
    await page.setCookie(...cookies);
    await page.goto("https://httpbin.dev/cookies");

    console.log(await page.content())
    browser.close();
}

run();
```





 

    



Scale Your Web Scraping

Anti-bot bypass, browser rendering, and rotating proxies, all in one API. Start with 1,000 free credits.

  No credit card required  1,000 free API credits  Anti-bot bypass included 

 [Start Free](https://scrapfly.io/register) [View Docs](https://scrapfly.io/docs/onboarding) 

 Not ready? Get our newsletter instead. 

 

## Explore this Article with AI

 [ ChatGPT ](https://chat.openai.com/?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-save-and-load-cookies-in-puppeteer) [ Gemini ](https://www.google.com/search?udm=50&aep=11&q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-save-and-load-cookies-in-puppeteer) [ Grok ](https://x.com/i/grok?text=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-save-and-load-cookies-in-puppeteer) [ Perplexity ](https://www.perplexity.ai/search/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-save-and-load-cookies-in-puppeteer) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-save-and-load-cookies-in-puppeteer) 



 ## Related Articles

 [  

 nodejs headless-browser 

### How to Web Scrape with Puppeteer and NodeJS in 2026

Introduction to using Puppeteer in Nodejs for web scraping dynamic web pages and web apps. Tips and tricks, best practic...

 

 ](https://scrapfly.io/blog/posts/web-scraping-with-puppeteer-and-nodejs) [  

 http 

### How to Handle Cookies in Web Scraping

Introduction to cookies in web scraping. What are they and how to take advantage of cookie process to authenticate or se...

 

 ](https://scrapfly.io/blog/posts/how-to-handle-cookies-in-web-scraping) [     

 blocking nodejs 

### Puppeteer Stealth: Complete Guide to Avoiding Detection

Complete guide to puppeteer-extra-plugin-stealth for avoiding bot detection. Learn how detection works, configure stealt...

 

 ](https://scrapfly.io/blog/posts/puppeteer-stealth-complete-guide) 

  ## Related Questions

- [ Q How to save and load cookies in Selenium? ](https://scrapfly.io/blog/answers/how-to-save-and-load-cookies-in-selenium)
- [ Q How to save and load cookies in Python requests? ](https://scrapfly.io/blog/answers/save-and-load-cookies-in-requests-python)
- [ Q How to load local files in Puppeteer? ](https://scrapfly.io/blog/answers/how-to-load-local-files-in-puppeteer)
- [ Q How to wait for a page to load in Puppeteer? ](https://scrapfly.io/blog/answers/how-to-wait-for-page-to-load-in-puppeteer)
 
  



   



 Run headless browsers at scale, **1,000 free credits** [Start Free](https://scrapfly.io/register)