Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

309
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda