sharing storage key between 2 different extensions?

1,946 views
Skip to first unread message

Adolfo Rodriguez

unread,
Jan 31, 2013, 9:56:11 PM1/31/13
to chromium-...@chromium.org
Hi, I want to share an storage key between 2 extensions.

For the extension doing the set this always works with both chrome.storage.sync and chrome.storage.local. Alter message is always shown correctly.

var storage = chrome.storage.sync;
storage.set({'Id': data.Id + ''}, function() {
       storage.get('Id', function(items) {
        alert(items.Id);
       });
});

Code is run from the javascript linked to a html browser_action.

However, for the extension trying to do the get:

var storage = chrome.storage.sync;
        storage.get('Id', function(items) {
        alert(items.Id);
        });

with both, sync and local, I get always a value of 'undefined'. "storage" is defined within the permissions key in manifest. The only thing that makes me wonder is that the get code is placed on the javascript associated to a popup opened from a custom menu. Is it required to be created in the background?

Any idea what is wrong in my configuration?

Thanks

Benjamin Kalman

unread,
Jan 31, 2013, 10:09:40 PM1/31/13
to Adolfo Rodriguez, chromium-...@chromium.org
Unless "data.Id" is undefined in your example, it looks like it should work. Could you file a bug with repro steps and a simple extension and assign to me?

Cheers,
Ben.


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msg/chromium-extensions/-/jnd3bZlvdlsJ.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.

Adolfo Rodriguez

unread,
Jan 31, 2013, 11:07:28 PM1/31/13
to chromium-...@chromium.org, Adolfo Rodriguez
Done. Thanks Issue 173576

Jeffrey Yasskin

unread,
Feb 1, 2013, 2:53:50 AM2/1/13
to Benjamin Kalman, Adolfo Rodriguez, chromium-...@chromium.org
https://code.google.com/p/chromium/codesearch/#chrome/src/chrome/browser/extensions/api/storage/sync_or_local_value_store_cache.cc&l=69
implies to me that chrome.storage is per-extension and there's no way
to share storage between extensions. Also, allowing that sharing would
seem to be a security hole. Am I missing something?

Benjamin Kalman

unread,
Feb 1, 2013, 9:38:46 AM2/1/13
to Jeffrey Yasskin, chromium-...@chromium.org, Adolfo Rodriguez

Heh, I missed the 2 different extensions part, I read it as 2 different places within the one extension.

Storage is very definitely isolated between extensions, there is no way to share data.

James Mortensen

unread,
Feb 1, 2013, 10:29:37 AM2/1/13
to Benjamin Kalman, Jeffrey Yasskin, chromium-...@chromium.org, Adolfo Rodriguez
If you can postMessage between two extensions, then you could sync up the storage in both extensions.  Just a thought....

James
--
James Mortensen
Project Manager, VoiceCurve, Inc.
866-707-4590
james.m...@voicecurve.com

Abraham Williams

unread,
Feb 1, 2013, 1:22:58 PM2/1/13
to James Mortensen, Benjamin Kalman, Jeffrey Yasskin, chromium-...@chromium.org, Adolfo Rodriguez
You can send messages between extensions. Making sure that data between the two extensions are synced and accurate will be up to you however.



Abraham
--
This email is: [ ] shareable [x] ask first [ ] private

Adolfo Rodriguez

unread,
Feb 1, 2013, 1:46:09 PM2/1/13
to chromium-...@chromium.org, James Mortensen, Benjamin Kalman, Jeffrey Yasskin, Adolfo Rodriguez
Thanks all for this great analysis. 

I did not know that storage runs in a per extension protected space. Not sure about the security hole since it can be left up to the developer to choose the right scope and decide if he want to share the data or nor. But not a big deal if it does not work like that.

Kalman, can you please close the issue then? Issue 173576

Thanks for your great feedback

Benjamin Kalman

unread,
Feb 1, 2013, 1:57:10 PM2/1/13
to Adolfo Rodriguez, chromium-...@chromium.org, James Mortensen, Jeffrey Yasskin
It's not a security hole: sharing data via postMessage (as others have suggested in this thread) is an explicit collaboration between two extensions, whereas making storage a shared area between all extensions would be implicit and a world of pain and confusion.
Reply all
Reply to author
Forward
0 new messages