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

243
Visualizações
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 Respostas
Responde à pergunta

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