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

102
Views
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 answers
Answer question

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 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!