Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

105
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda