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

235
Visualizações
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 à 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