Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
How to set cookies in a variable and use it again: PUPPETEER

i'm trying to insert ALL browser cookies in a variable and then use it again later.

My attempt:

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

(async () => {
  const browser = await puppeteer.launch({ 
    headless: false,
    executablePath: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
 const page = await browser.newPage();
 await page.goto('https://www.google.com/');

Below, it's my code to get cookies, and it work, but now it print a error message.

 const client = await page.target().createCDPSession();
 const all_browser_cookies = (await client.send('Network.getAllCookies')).cookies;
 const current_url_cookies = await page.cookies();
 var third_party_cookies = all_browser_cookies.filter(cookie => cookie.domain !== current_url_cookies[0].domain);
 

and below it's the seccond page (that will use cookies)

 (async () => {
    const browser2 = await puppeteer.launch({
    });
    const url = 'https://www.google.com/';
    const page2 = await browser2.newPage();

  try{
  await page2.setCookie(...third_party_cookies);
  await page2.goto(url);
  }catch(e){
      console.log(e);
  }
  await browser2.close()
  })();

})();

until yesterday it works, but today it's appearing this message error:

Error: Protocol error (Network.setCookies): Invalid parameters Failed to deserialize params.cookies.expires - BINDINGS: double value expected at position 662891

Anyone know what is it?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Ok, the solution is here: https://github.com/puppeteer/puppeteer/issues/7029

You are saving an array of cookies and page.setCookie only works with one cookie. Yo have to iterate trought your array like that:

for (let i = 0; i < third_party_cookies.length; i++) {
    await page2.setCookie(third_party_cookies[i]);
}
about 4 years ago · Juan Pablo Isaza Report

0

@julio-codesal's suggestion is ok, but according to the puppeteer documentaion it is ok to use page.setCookie with an array, as long as you destructure it, e.g.:

await page.setCookie(...arr)

source: https://devdocs.io/puppeteer/index#pagesetcookiecookies

Not exactly sure what it is, but the error the OP has is something else.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!