问题
I have a chrome extension that does spell check. I want to implement the feature to 'add a word to dictionary' but I read that chrome extension api does not allow reading and writing to disk.
currently my dictionary is an array of strings:
var dictionary = ["google", "apache", "microsoft"];
My question is this: How should I properly store my dictionary? And how can I change its content during run time for the 'add to dictionary feature'?
回答1:
As Josh mentioned, use the chrome storage API. For example chrome.storage.sync.set() and chrome.storage.sync.get() automatically syncs the saved data between the different devices the user uses - it's very nice both for developers and users.
http://developer.chrome.com/extensions/storage.html
回答2:
You may use local storage of the browser. However if you want to be really flexible you may use nodejs and sockets. That's how I made my extension. I used nodejs, which has an access to the user's disk and sockets to communicate with the node app. The only one problem is that the user should install the module.
来源:https://stackoverflow.com/questions/18580583/save-program-state-in-chrome-extension-between-uses