In my html file I have a simple table and a couple of buttons that allow adding/removing rows. If I store that html in popup.html, then every time I close chrome extension the session disappears. That is if I added some rows and put some values to the cells of that table, once I go from my extension, these rows and values disappear when I click on the extension again.
As a solution I saw putting that html to background.html and retrieving that code from popup.js:
// listeners to save/restore document.body
window.addEventListener("unload", function(event) {
chrome.extension.getBackgroundPage().docBody = document.body;
});
window.addEventListener("load", function(event) {
var
docBody = document.body,
lastDocBody = bgPage.docBody;
if (lastDocBody)
docBody.parentElement.replaceChild(document.importNode(lastDocBody,true),
docBody);
});
However, it doesn't output any content of background.html to my extension.
The question is general: I would like to save the last state of my table, no matter if I closed the extension or not. How can I do this?
Or in particular, how can I load/save page from/to background.html and upload its content to popup.js