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

124
Views
How to pass main website's secured session cookie to web worker and use it there to call APIs

We use a secure session cookie and the back-end set the cookie through the login API. Http requests are cross-origin. I want to use web-workers to do some calculations and call certain APIs. cookies will be lost in web worker API calls despite using credentials: 'include'. What can I do if I don't want to pass back API calls to the main thread?

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

0

Actually, the web worker HAS main thread cookies including secured ones. to use credentials you should mention credentials: 'include' in fetch request params as follows:

   fetch('https://example.com/profile', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(data),

      // this line is important:
      credentials: 'include', // include, same-origin or omit ... as your conditions
    
    })
    .then(response => response.json())
    .then(data => {
      console.log('Success:', data);
    })
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!