Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppeteer: get localStorage from a website

I need to take with Puppeteer all the data that a website saves: cookies and localStorage (for example after Login). I have read all Puppeteer documentation but I can not find anything about localStorage.

enter image description here

I can get cookies but I don't know to get localStorage. For example:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch()
  const page = await browser.newPage()
  await page.goto('https://www.twitter.com/')

  //
  // code for login
  //

  const returnedCookie = await page.cookies();  
  console.log(returnedCookie)
  // const localStorage = ??
  // console.log(localStorage)

  await browser.close()
})()
like image 446
kurtko Avatar asked Apr 17 '19 10:04

kurtko


1 Answers

easier way that worked for me

const localStorage = await page.evaluate(() => Object.assign({}, window.localStorage));

like image 91
Guido Dizioli Avatar answered Sep 21 '22 12:09

Guido Dizioli