Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!