admin管理员组文章数量:1296392
I need to store a users profile and his preferences in a localStorage object \ cookies in a way that they'll be accessible(readable) and writable from both the web-app, and the chrome extension (that are basically part of the same product).
I found this cool library and this article that specifies how to use it.
The problem is that xauth is down, and so is the server page that is required to use the library.
Any alternatives
I need to store a users profile and his preferences in a localStorage object \ cookies in a way that they'll be accessible(readable) and writable from both the web-app, and the chrome extension (that are basically part of the same product).
I found this cool library and this article that specifies how to use it.
The problem is that xauth is down, and so is the server page that is required to use the library.
Any alternatives
Share Improve this question edited Jul 9, 2014 at 20:51 Charles 51.4k13 gold badges106 silver badges144 bronze badges asked Jul 9, 2014 at 10:58 Oleg BelousovOleg Belousov 10.1k14 gold badges74 silver badges128 bronze badges 7-
Err. Context scripts share access to domain's
localStorage
. – Xan Commented Jul 9, 2014 at 11:00 - the domain is chrome-extension://{id} thus not accessible from the web, or am I missing something? – Oleg Belousov Commented Jul 9, 2014 at 11:01
-
Note: content scripts. If you inject a script into the page in question,
localStorage
will be shared. – Xan Commented Jul 9, 2014 at 11:02 - So, basically you are suggesting to add the web-app's domain to the list of matching domains, and then the chrome.localStorage object will be available from the web, even on non-chrome browsers?, doesn't sound rational – Oleg Belousov Commented Jul 9, 2014 at 11:06
-
What's
chrome.localStorage
? Are you confusing things withchrome.storage.local
? – Xan Commented Jul 9, 2014 at 11:07
2 Answers
Reset to default 9You can use both localStorage
and cookies.
If you inject a content script in the web app's page, its
localStorage
is shared with domain's own storage. You can then municate with your background script to pass information.If you include
"cookies"
permission in your manifest, you can manipulate cookies usingchrome.cookies
API.
Edit: You can also make your extension externally connectable from the web app to maintain synchronization of the changes.
Update 2016
This cross-storage from zendesk is a great alternative to the 2 librarys that you mention
Even better you can config which client site/domain has a specific permission (either to get, set, delete)
Sample codes:
Hub
// Config s.t. subdomains can get, but only the root domain can set and del
CrossStorageHub.init([
{origin: /\.example.$/, allow: ['get']},
{origin: /:\/\/(www\.)?example.$/, allow: ['get', 'set', 'del']}
]);
Note the $ for matching the end of the string. The RegExps in the above example will match origins such as valid.example., but not invalid.example..malicious..
Client
var storage = new CrossStorageClient('https://store.example./hub.html');
storage.onConnect().then(function() {
return storage.set('newKey', 'foobar');
}).then(function() {
return storage.get('existingKey', 'newKey');
}).then(function(res) {
console.log(res.length); // 2
}).catch(function(err) {
// Handle error
});
本文标签: javascriptSharing a local storage object across a webapp and a Chrome extensionStack Overflow
版权声明:本文标题:javascript - Sharing a local storage object across a web-app and a Chrome extension - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741611014a2388258.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论