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

135
Visualizações
Overwrite native JS function with Chrome Extension (manifest V3)

my aim is to override the default setInterval JS function in all pages with a browser extension (by injecting my javascript code just at the beginning of pages). This script should run before any other script, jQuery included. My latest attempt (not working) is this:

manifest.js

...
"content_scripts": [
    {
    "matches": ["<all_urls>"],
    "js": ["content.js"],
    "run_at": "document_start",
    "all_frames": true
    }
],
    "background": {
    "service_worker": "background.js"
},  
    "permissions": [
    "scripting"
],  
    "host_permissions": ["<all_urls>"],
...

content.js

 function do_newInterval() {
      window.setInterval = function setInterval() {console.log('hello')}
 };

 chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
      if (msg.type === 'newInterval') { do_newInterval(); }
 });

background.js

 chrome.tabs.onUpdated.addListener(async () => {
    let activeTab=await chrome.tabs.query({ active: true, 
    lastFocusedWindow: true })
    chrome.tabs.sendMessage(activeTab[0].id, {  type: "newInterval" 
    });
 })

Unfortunately the code to replace the setInterval function is run after other page scripts are executed!

Could you please show me the right way to make my JS run as first?

Thank you!

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