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

103
Visualizações
Creating multiple cookie contexts using the `fetch` API

I am writing a Web Extension that attempts to fetch pages from a session based API in parallel. The API uses cookies to store the session information. So, the following sequence of commands would work:

// Fetch sequence 1
await fetch("https://url.endpoint/start_session");
const usefulData1 = await fetch("https://url.endpoint/navigate_to_X",
  { credentials: "include" });
// Fetch sequence 2
await fetch("https://url.endpoint/start_session");
const usefulData2 = await fetch("https://url.endpoint/navigate_to_Y",
  { credentials: "include" });

I would like to run Fetch sequence 1 and Fetch sequence 2 in parallel. The problem is, every time I access https://url.endpoint/start_session I get sent back a new set of cookies, and all fetch requests with { credentials: "include" } use the currently set cookies (which get overridden when start_session returns).

My question is: is there a way to set up multiple "sessions" so that these requests can run in parallel with their own cookies? Or is there some other workaround? (It appears the fetch api will not allow you to get or set the Set-Cookie header manually...)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you want to await the completion of two promises at once, you can use Promise.all. This will create a new promise that only resolves when all promises passed in to it complete, but still lets them run in parallel. In this case, I would await the start_session endpoint, then await a Promise.all of the other two, like this:

await fetch("https://url.endpoint/start_session");
const [usefulData1, usefulData2] = await Promise.all([
  fetch("https://url.endpoint/navigate_to_X", { credentials: "include" }),
  fetch("https://url.endpoint/navigate_to_Y", { credentials: "include" })
])
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