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

179
Vistas
Open a HTML page on new tab on the event of Button click from Popup of Chrome Extension and send data retrieved from current tab

There is this SO question similar to my question - Send message to background page, update the html, and then show it in a tab. But I'm first running a JS script in the context of the current tab i.e., this script to find the highlighted word is injected into the current web page. So, I'm unable to use chrome APIs.

I am trying to make a Chrome extension that fetches the meaning of the highlighted/selected word after clicking a button on the extension's popup. Here's my popup.html:

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="button.css" />
  </head>
  <body>
    <button id="meaning" type="button">Find Meaning</button>
    <script src="popup.js"></script>
  </body>
</html>

Here's my popup.js:

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

  chrome.scripting.executeScript({
    target: { tabId: tab.id },
    function: findMeaning,
  });
});

function findMeaning(){
  const word = window.getSelection().toString();
  // code to send the word to another HTML file that opens in a new tab
}

Let's say, I've a mean.html in my extension's directory and it is like:

<html>
<body>
<p id="para"> the answer appears here </p>

<script>
 function showMeaning(wordToFindMeaning) {
   const meaning = await fetch(`someAPI/${wordToFindMeaning}`);
   document.getElementById('para').innerText = meaning;
}
showMeaning(word);
</script>

How do I pass the highlighted word from popup.js to this mean.html. I don't know if chrome.storage API could be used. If we use it, the word shouldn't persist in the memory after the mean.html page is opened and the word meanings are displayed.

about 4 years ago · Santiago Trujillo
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