Search code examples
google-chrome-extension

Chrome extension popup resets even after changing its contents


In my chrome extension, I had to change popup html from background. Changes affects then and after clicking again in extension icon, the unchanged popup is showing. Why?


Solution

  • Every time you click away from your popup window, the window is reset. A way to fix this would be to use your background page to store session data, in your popup.js, do something like this:

    chrome.runtime.getBackgroundPage(function(bg){
      if(bg.myDataHTML){
        document.body.innerHTML = bg.myDataHTML; 
      }
      setInterval(function(){
        bg.myDataHTML = document.body.innerHTML
      },1000);    
    
      //do the rest of your work here.
    })
    

    I typically do everything in my popup inside that anonymous function to give me access to the libraries defined within my background page.