Save program state in chrome extension between uses

久未见 提交于 2021-02-05 07:45:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!