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

83
Vistas
Are webextension webrequest interceptions supposed to work in Ajax/Fetch?

Are web extension supposed to intercept web request in scripting too?

I created a extension with the following permissions

  "permissions": [
    "webRequest", 
    "webRequestBlocking", 
    "<all_urls>"
  ]

The following background.js is working great in a browser tab

function listener(details) {
    let filter = browser.webRequest.filterResponseData(details.requestId);
    let url    = details.url;
    let method = details.method;
    // for other usefull informations
    // see https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/onBeforeRequest#details    
    
  filter.onstart = event => {
    if (url.indexOf("foo.json") != -1)
    {
        console.log("started");
        let encoder = new TextEncoder();
        filter.write(encoder.encode(`<html><body>OK</body></html>`));
        filter.close(); 
    }
    else
    {
        filter.disconnect();
    }
  }
}

browser.webRequest.onBeforeRequest.addListener(
  listener,
  {urls: ["<all_urls>"]},
  ["blocking"]
);

Working great = it serves the text "OK" if I add "foo.json" for any url on any site. This is what I expected.

But not at all in a script

fetch('foo.json').then(function(response) {
  if(response.ok) {
    debugger;
  } else {
    console.log('network exception');
  }
})
.catch(function(error) {
  console.log('fetch failed: ' + error.message);
});

Response is not ok : it contains the original 404 emitted by site

about 4 years ago · Santiago Gelvez
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