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

136
Vistas
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 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