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

235
Views
Why arent my headers registered on a chrome extension?

I have the following code:

chrome.webRequest.onBeforeSendHeaders.addListener(function (data){
    for (let header of data.requestHeaders) {
        if (header.name === "User-Agent") {
            chrome.storage.sync.get({pua: "Non-Set"}, function (result) {
                data.requestHeaders[data.requestHeaders.indexOf(header)].value = result.pua;
            })
            
        }
    }
    return {requestHeaders:data.requestHeaders}

    
    
}, {urls: ["<all_urls>"]}, ["requestHeaders", "blocking", "extraHeaders"])

It is supposed to get the option value the user sets, and return that as the user-agent header, but it does not work at all! I used netcat, and my user-agent is normal!

However, if I hardcode the header value, it works! I am getting really annoyed.

I tried using new Promise, and awaiting it but that still didn't work! How can I do this?

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

0

Since chrome.storage.sync.get() is asynchronous, there is no way to assure the callback of addEventListner return after the callback of chrome.storage.sync.get() is executed.

The alternative is that the request is always cancelled by the callback of addEventListner, and send modified request in the callback of chrome.storage.sync.get().

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!