javascript - Save last session of chrome extension -


in html file have simple table , couple of buttons allow adding/removing rows. if store html in popup.html, every time close chrome extension session disappears. if added rows , put values cells of table, once go extension, these rows , values disappear when click on extension again.

as solution saw putting html background.html , retrieving code popup.js:

// listeners 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, doesn't output content of background.html extension.

the question general: save last state of table, no matter if closed extension or not. how can this?

or in particular, how can load/save page from/to background.html , upload content popup.js

you have use 1 of storage apis provided.

best 1 use chrome.storage, can use localstorage inside chrome extension pages. see this question comparison. don't need background page either.

do note: cannot store dom nodes directly in such storage, since data has json-serializable, , dom nodes contain circular references.

so you'll need store data used add rows instead of rows themselves, , add them again when restoring state. idea anyway store "raw" data.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -