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

355
Vistas
How do you get the URL with activeTab inside of a webRequest callback fn?

Objective

I'm trying to get the active tab's url when the user goes to a new website. The chrome web store has suggested that I remove the tabs permission and use activeTab instead. I don't have a content script and only need the active URL.

Current Code

I currently get the active tab and save it to a global variable with the tabs permission:

let ACTIVE_URL = '';

chrome.tabs.onActivated.addListener((_activeInfo)=> {
    chrome.tabs.query({active: true}, (tabs) => {
        ACTIVE_URL = tabs[0].url || tabs[0].pendingUrl || ACTIVE_URL;
    });
});

chrome.tabs.onUpdated.addListener((_tabID, _changeInfo, tab) => {
    ACTIVE_URL = tab.url || ACTIVE_URL;
});

Docs say it's possible?

this question, and woxxom's comments seem to indicate that it's not possible. But according to activeTab documentation, activeTab allows you to

Intercept network requests in the tab to the tab's main frame origin using the webRequest API. The extension temporarily gets host permissions for the tab's main frame origin.

So it seems like this is possible (in place of placeholder chrome.getActiveUrl();).

chrome.webRequest.onBeforeRequest.addListener(
    (webRequest) => {
        const activeURL = ACTIVE_URL // chrome.getActiveUrl();
        if (activeURL === url.im.looking.for) {
            return {cancel: true};
        }
        return {cancel: false};    
    },
    {
        urls: ["http://*/*", "https://*/*"],
        types: ['main_frame']
    },
    ['blocking']
);

Async alternatives

this question says it's not possible to use an async function inside of the onBeforeRequest listener.

Question

How do you get the URL with activeTab inside of a webRequest callback fn?

about 4 years ago · Juan Pablo Isaza
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