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

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

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