window.localStorage is not available in a chrome packaged app. Use chrome.storage instead?

620 views
Skip to first unread message

Alex Banks

unread,
Apr 15, 2016, 2:24:41 PM4/15/16
to Firebase Google Group
I am trying to use Firebase in a chrome packaged app.  So far I have GitHub authorization via firebase working and I am able to connect and listen for data.  It all seems to work...

However, the console is riddled with errors.  Everything that Firebase is trying to save to window.localStorage is not working because there is no localStorage in a chrome app.  You are supposed to use chrome.storage.local instead.  I would simply reference local storage from chrome.storage.local but it works a little different from local storage because it uses get and set functions to read and write data.

What is the best way to incorporate Firebase in a chrome packaged app.  Currently, I am bundling up the firebase npm with webpack and it runs from the chrome app.  Is there another firebase library that I should reference that is not so browser dependant.

It is hard to find any info on how to build a Chrome app that uses firebase.

Kato Richardson

unread,
Apr 15, 2016, 2:45:54 PM4/15/16
to Firebase Google Group
Hi Alex,

I wonder if you could just polyfill the window.localStorage variable to chrome.storage.local? Maybe wrap the get/set methods?

Most likely, the long polling fallbacks (which are used if web sockets are unavailable) will bust too as I think they use a lot of document.createObject() logic and iframes, but that might not be an issue if websockets are always available to chrome apps?

I'll try to get someone a little more versed in the internal workings of the JavaScript SDK to chime in here, but I'm guessing this just isn't really supported.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/76d3362f-28bc-4e14-94d7-8cce28eb051d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Alex Banks

unread,
Apr 26, 2016, 9:46:55 AM4/26/16
to Firebase Google Group
In the chrome app I am actually forcing websockets with:

Firebase.INTERNAL.forceWebSockets();

This solved some issue awhile back.

I am assuming a polyfill would work.  One of the challenges is the chrome.storage.local is async and localStorage is sync.

So far my app seems to be working.  I am sure it may break if I tried to turn some security features on?  The issue is that pesky error shows up every time.

Also, when I use the firebase.js library for authorization from a chrome app I ran into some issues.  I could not do the authorizeWithOAuthPopup.  I had to auth directly with Github and then use authorizeWithOAuthToken.  So from the chrome app I have to do both of these things.  It works, but I also get this error: before unload is not available in packaged apps.

What is the best library to use when building a Chrome APP?  The JavaScript library?  or should I be trying to use some firebase library that was built for Android or something?

Alex Banks

unread,
Apr 26, 2016, 9:46:55 AM4/26/16
to Firebase Google Group
Hello Kato,

Thanks for looking into this.  I believe that one of the challenges would be that chrome.storage.local is async and localStorage is sync.

I've ran into a few problems using Firebase with a Google Chrome Packaged App.  I had to build an oAuth work around that actually causes two authorizations to occur.  I also get errors about before unload not being available in packaged apps.

What is the best firebase library to use with packaged apps?  Firebase.js?  Or some other library, like the one for android maybe?  Is there a scaled back library that does not interact directly with the browser so much?

Thanks Kato.  -Alex

On Friday, April 15, 2016 at 11:45:54 AM UTC-7, Kato Richardson wrote:
Reply all
Reply to author
Forward
0 new messages