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

240
Vistas
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 Respuestas
Responde la pregunta

0

Try removing body from document.body.style

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