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

204
Vistas
How to use chrome.identity.getProfileUserInfo in chrome.webRequest.onBeforeRequest?

How can I use a Chrome extensions API that can be used with a callback function, such as chrome.identity.getProfileUserInfo, in chrome.webRequest.onBeforeRequest?

For example, I have a part of script similar to:

chrome.webRequest.onBeforeRequest.addListener(
  function (request) {
    return { redirectUrl: `https://example.com` };
  },
  // filters here. 
  // permissions here. 
)

The above works, it redirects request attempts to the https://example.com.

But the following, with wrapping the code in a callback function, the return/redirectUrl part is ignored and it doesn't work; it doesn't redirect.

chrome.webRequest.onBeforeRequest.addListener(
  function (request) {

    chrome.identity.getProfileUserInfo(function (profileUserInfo) {
      console.log(profileUserInfo.email);

      return { redirectUrl: `https://example.com` };
    });
  },
  // filters here. 
  // permissions here. 
)

This is a synchronous way that webRequest.onBeforeRequest is only capable of, correct? I use these callbacks, synchronous way because I learnt the chrome extensions API doesn't support an asynchronous way (e.g. async/await, Promise) as I asked on SO other day: javascript - async in chrome.webRequest.onBeforeRequest? - Stack Overflow

So, is it possible, to use chrome.identity.getProfileUserInfo in chrome.webRequest.onBeforeRequest? Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

No, you can't. "chrome.identity.getProfileUserInfo" like most "chrome." methods take time to do, therefore the callback function. "chrome.webRequest.onBeforeRequest" only supports the "blocking" option but not "asyncBlocking". But in your case, you could easily assign the ProfileUserInfo to a variable beforehand somewhere in your background script and use it like that.

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