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

110
Vistas
Why is my local storage key saying undefined while using it in the content script for Chrome extension development?

I'm trying to save the data coming from my popup.js into the local storage of the website in which the popup was opened. I am using the chrome.runtime.onMessage.addListener() to get the data into my content script and saving it in the local storage. While checking it in real time on the browser, the key 'url' in the local storage briefly gets set to the data being sent but after less than one second, says 'undefined'. How do I fix this? Will this be easier to accomplish using cookies?

contenscipt.js

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        localStorage['url'] = request.url_;
        if(window.location.href.includes(request.url_)){
            document.querySelector('body').innerHTML= "Full Page has been replaced with this";
        }
    }
  );

popup.js

function ping(url){
  chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
    chrome.tabs.sendMessage(tabs[0].id, {url_: url}, function(response) {
      if(chrome.runtime.lastError) {
        setTimeout(ping, 1000);
      }
    });
  });
}

document.getElementById('id_save').onclick = () => {
    ping(document.getElementById('id_memo').value);
}
about 4 years ago · Juan Pablo Isaza
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