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

228
Vistas
WebExtension : using webrequest to push my content for matching url, is webRequest.StreamFilter.onstart the way to go?

I want to write a webextension that pushes fake json content when accessing any url that matches a pattern.
I started with the MSDN doc.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/StreamFilter/ondata

code is rather straightforward

function listener(details) {
  let filter = browser.webRequest.filterResponseData(details.requestId);
  let decoder = new TextDecoder("utf-8");
  let encoder = new TextEncoder();

  filter.ondata = event => {
    let str = decoder.decode(event.data, {stream: true});
    // Just change any instance of Example in the HTTP response
    // to WebExtension Example.
    str = str.replace(/Example/g, 'WebExtension Example');
    filter.write(encoder.encode(str));
    filter.disconnect();
  }
}

browser.webRequest.onBeforeRequest.addListener(
  listener,
  {urls: ["https://example.com/*"], types: ["main_frame"]},
  ["blocking"]
);

But this is not what.
I don't want to (wait for then) alter content. I want to push my content right away.

So I changed the listener for

  filter.onstart = event => {
    var url = event. ???
    if (url.indexOf("any string I'd like to look for")) 
    {
      filter.write(encoder.encode("some text to display"));
      filter.close(); 
    }
    else // I'm not interested in you, just process as usual
    {
      filter.disconnect()
    }
  }

My aim is to catch any url, look for a pattern in it and display my content if it matches.
Is looking for onstart the right way to do it?

  • If yes, I found strange than googling does not return more exemples and I can't find doc for the event that occurs for the on start.
    How is this event called? Where can I find doc for it (and events that occured ondata onclose...)?

  • If no,
    what will be the right way for a web extension to intercept a page request to push (or not) its content instead.

Will my idea of page substitution work if I'm using Ajax/fetch to get it?
Will I be able to set the mimetype too? (I want to push json content)

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