Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

268
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda