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

238
Views
My chrome extension change itself background not my web page background?

I am creating my first chrome extension that manipulate DOM to change page background once i click a button in the extension, but unfortunately, the extension manage to change itself background instead of the web page and i need to know the reason for that:

manifest.json

{
  "name": "Demo",
  "description": "certain description!",
  "version": "1.0",
  "manifest_version": 3,
  "background": {
    "service_worker": "background.js"
  },
  "permissions": [
    "storage",
    "declarativeContent",
    "activeTab",
    "scripting"
  ],
  "action": {
    "default_popup": "popup.html"
   }
}

popup.js

 const button = document.getElementById('change-bg');

 button.addEventListener('click, () => {
   let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
   chrome.scripting.executeScript({
     target: { tabId: tab.id },
     function: changeBackground()
  })
 })
}
function changeBackground() {
   document.body.style.background = "blue"
}

This extension seems to get the body of the extension not the body of the page, and since i am using chrome.scripting.executeScripts, my extension should inject my code into the active page but this doesn't happen.

What am i doing wrong here?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try removing body from document.body.style

about 4 years ago · Juan Pablo Isaza 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!