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

102
Views
How to make a chrome extension work immediately on a new page

I am trying to get my extension to act immediately upon a new page instead of when I click a button. For example, this code works in terms of changing the words on the page, but only once I click a button from my default popup. How can I make it to where it acts immediately once a user changes pages. I tried making a new .js file but it won't do anything.

function change(){
  const text = document.querySelectorAll("h1, h2, h3, h4, h5, p, li, td, caption, span, a")
for(let i=0;i<text.length;i++){
  if(text[i].innerHTML.includes("The")){
    text[i].innerHTML = text[i].innerHTML.replace("The","A")
  }
  
}
}
change();
almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use content_scripts.

manifest.json

{
  "name": "hoge",
  "version": "1.0",
  "manifest_version": 3,
  "content_scripts": [
    {
      "matches": [
        "<all_urls>"
      ],
      "js": [
        "matches.js"
      ]
    }
  ]
}

matches.js

function change(){
  const text = document.querySelectorAll("h1, h2, h3, h4, h5, p, li, td, caption, span, a")
for(let i=0;i<text.length;i++){
  if(text[i].innerHTML.includes("The")){
    text[i].innerHTML = text[i].innerHTML.replace("The","A")
  }
  
}
}
change();
almost 4 years ago · Santiago Trujillo Report
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!