Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!