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

311
Vistas
How to modify the content of popup page in chrome extension?

I am trying to create a simple Chrome extension that has a button in the popup window, and when the user clicks that button, some text in that popup changes. Here is what I have:

popup.html file:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <button id="myButton">Button</button>
    <p id="myText">hello</p>
    <script src="popup.js"></script>
  </body>
</html>

popup.js file:

let myButton = document.getElementById("myButton");

myButton.addEventListener("click", async () => {
  let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });

  chrome.scripting.executeScript({
    target: {tabId: tab.id},  // This is probably wrong???
    function: doSomething,
  });
});

function doSomething() {
  console.log("button is clicked");
  document.getElementById("myText").innerHtml = "foo bar";
}

I am able to see "button is clicked" in the console, but do not see the content of popup change from "hello" to "foo bar". I suspect this is because the target I used in executeScript is wrong, but I am not sure what's the right way to fix it. Any thoughts?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It should be:

document.getElementById("myText").innerHTML = "foo bar";

instead of:

document.getElementById("myText").innerHtml = "foo bar";
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