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

136
Visualizações
async in chrome.webRequest.onBeforeRequest?

Is it possible to work with async/await in the chrome API's webRequest.onBeforeRequest?

The following does work; From "working" I mean it does block/cancel the request as I expect.

chrome.webRequest.onBeforeRequest.addListener(
  function (details) {
    console.log("URL intercepted:", {url: details.url, type: details.type,}); 
    let match = details.url.match(/:\/\/(www\.)?someSiteThatIWantAvoidRawIp\.org(\/)?$/); // you are accessing this url on your chorme 

    if (match)
    {
      console.log("URL blocked:", { url: details.url, type: details.type, match: match, });
      return { cancel: true };
    }
  },
  {
    urls: [
      "<all_urls>"
    ], 
    types: ["main_frame",]
  },
  ["blocking",]
);

However, the following does not work; It is supposed to block/cancel the request after waiting the await, but the cancel doesn't work but the page shows up without a connection error.

chrome.webRequest.onBeforeRequest.addListener(
  async function (details) {
    console.log("URL intercepted:", {url: details.url, type: details.type,}); 
    let match = details.url.match(/:\/\/(www\.)?someSiteThatIWantAvoidRawIp\.org(\/)?$/); 

    let ip = await axios.get('https://someSiteThatChecksMyIp.org', {}) // this gets my ip 
        .then(r => {
            console.log(r);
            return r.data;
        })
        .catch(e => {
            console.log(e);
        });

    if (match)
    {
        if (ip == "123.123.123.123") // assume my raw ip 
        {
            console.log("URL blocked:", { url: details.url, type: details.type, match: match, });
            return { cancel: true };
        }
    }
  },
  {
    urls: [
      "<all_urls>"
    ], 
    types: ["main_frame",]
  },
  ["blocking",]
);

What's incorrect with my setup? Thanks.

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