I recommend you using asyncStorage over localStorage, is an asynchronous version of localStorage, with the same api and the benefits of IndexedDB.
You can see the code and learn how to use it reading the comments of the file:
https://github.com/mozilla-b2g/gaia/blob/master/shared/js/async_storage.js