Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

New key-value storage API for devtools

4 views
Skip to first unread message

Brian Grinstead

unread,
Feb 26, 2015, 2:51:22 PM2/26/15
to dev-developer-tools
Hello,
I'm sending an update about a new API that can be used in devtools to
store application data. It's a modification of the async-storage API
used in Gaia that uses Promises instead of callbacks.

It exposes an asynchronous localStorage API backed by Indexed DB, so you
can do things like:

asyncStorage.setItem("key", "newvalue").then(function() {
console.log("new value stored");
asyncStorage.getItem("key").then(function(value) {
console.log("The value of key is:", value);
});
});

See the header comment here for further information:
https://dxr.mozilla.org/mozilla-central/source/toolkit/devtools/shared/async-storage.js.

When would you use this instead of a pref? It makes sense for storing
things things that aren't actually configuration options. If it's an
option that a user may want to modify, stick with a pref. An example of
where this works better is keeping track of console input history (Bug
943306), which is ~50 user inputted strings of arbitrary length.
Another idea would be for storing breakpoint locations for a particular
page so they could be restored when opening and closing the toolbox.

Two things to be aware of when using this API:

1) There isn't yet a way in the browser UI to clear Indexed DB data, so
if it's something a user would likely to want to reset, there should be
some way to do so. In the case of console history, we are planning to
add a 'clearHistory()' jsterm helper in Bug 1134845. It would be
possible (and may or may not be a good idea) to add a button in the
options panel to 'reset devtools' that just wipes out everything and
maybe clears all devtools related prefs.

2) This API could be improved if it allowed multiple operations within a
single transaction. There is much discussion about why this would be
useful in https://bugzilla.mozilla.org/show_bug.cgi?id=866238 and
https://groups.google.com/d/msg/mozilla.dev.gaia/g5_eOE7YHWw/s8dH40HC8lsJ.
Since this is intended for use in devtools only (for now), we have a
chance to experiment with the API if we want to try to extend it this way.

Brian

0 new messages