How do I listen for Firebase Cloud Messaging messages in the background in a Google Chrome Extension? - firebase

I have a Google Chrome Extension that listens for GCM messages in a background script via chrome.gcm.onMessage.addListener. Our provider is planning to upgrade their infrastructure to use the latest Firebase Cloud Messaging which is no longer compatible with GCM. We've confirmed the gcm addListener API no longer receives messages after upgrading to FCM in the dev environment.
I've found migration guides for Android, iOS, and progressive web apps but none specifically for background scripts in Chrome extensions.
Some resources I've found:
Official Chrome Extension example but is specifically for authentication
Documentation for JavaScript, specifically PWAs
Upgrade notification from the Google Developers Blog

The extension that I mentioned in my question three years ago still exists today and continues to rely on the chrome.gcm extension API.
Recently we noticed the gcm.notification.badge value is no longer being passed along with the data object, instead we're seeing a gcm.notification.e property that I believe contains the badge value. I was unable to find any documentation on why that property changed but I did find an answer to my original question:
We are deprecating the chrome.gcm API and encourage you to move to Web
Push Notifications using VAPID authentication. This works on the Web,
in Chrome Extensions and in Chrome Apps. You can find more information
here:
https://developers.google.com/web/fundamentals/push-notifications/
Web Push Notifications offer a slightly different set of features from
the chrome.gcm API. Please file an issue or contact us directly if you
believe that it cannot satisfy your requirements.
Source: https://bugs.chromium.org/p/chromium/issues/detail?id=831532

Related

Persist Firebase Auth session in Google Workspace Add-on

I'm working on a Google Sheets add-on that needs to interact with existing web-app. The app uses Firebase for authentication. Firebase is not available as an "Advanced Google Service" and there is no official library (as well as official docs advice against using libraries in an add-on), so I'm using #firebase/auth in the client-side code.
The code is simple and the same as I'm using in the web-app (without FirebaseUI, but I've tried it as well) and because add-ons cannot use cookies or localStorage*, the Firebase cannot persist a local session.
Within the add-on we can only use Google Script Properties service, so I'm looking if there is a way to persist a session manually for the Firebase (like provide own "Storage" implementation, I've just done this for another node package I use in the add-on).
The question is mostly about Firebase and environment with no cookies/localStorage but other storage, but I may be missing some other way to use Firebase Auth with script add-ons.
Thanks for you help.
Edited: removed indexedDB, I've checked it in Console and accidentally switched from iframe to the top context, of course indexedDB is also unavailable in iframe (we should be sure the add-on works in Chrome).
* yes, we can ask user to go to the Chrome settings and select "Allow all cookies" but this is not an option for production.
I don't think there's any documented way to control the storage that Firebase Authentication beyond the picking from the options mentioned in the documentation on auth state persistence.
I think allowing you to provide a custom storage implementation would be a valid feature request, so I recommend asking for it here. I don't think the request comes up frequently though, so it may not get the priority you'd like. In that case: implementing the feature would require allowing the developer to specify their own storage in the public SDK, and then you in your project implementing your own storage provider similar to the storage providers in the SDK.

Can I use Firebase Analytic Web SDK for a Cordova App?

I'm developing a cross platform app: Web, PWA, iOS (Cordova) & Android (Cordova).
I use the same code base, and Firestore & Auth are working well on all the platforms using only the Web SDK.
However, when I add the Firebase Analytic plugin, it works as expected on the Web / PWA, but the iOS / Android apps do not seem to send back anything.
Is there a way to make Analytic works using only the Web SDK? Or is it mandatory to use a Cordova Plugin?
Thank you in advance for your help.
Note: I'm using Framework7 & VueJS
Edit 1
It seems that cordova is officially supported for analytic with the web SDK.
So the question becomes: do you have any idea why the implementation is working for "normal" app and break when on cordova?
https://firebase.google.com/support/guides/environments_js-sdk#other_environments
Edit 2
Now that I know that it should work, I'm trying harder to find solutions.
First, I observed in the Safari Console that on y web app, I can observe calls to https://www.google-analytics.com/g/collect every time I'm logging an event.
I do not observe those calls on the Cordova app, which is most probably the reason why I do not receive anything in my Firebase Analytics.
The question becomes: why are those call not made in cordova, considering the js the same?
Edit 3
Ok, I think I found the explanation:
Google Analytics from a file:// url
The question becomes: since Analytic is loaded automatically with firebase, how can I make this configuration?
Ideally, I would like a way to set the client id using a hash of my user uuid (as I said in my post, I'm using Firebase Auth).
How can I dynamically change the value each time a user connect to the app? Can Firebase directly take care of this?

Usage of Firebase for Google Auth in Firefox extension

I'm trying to use Firebase for Google Authentification in Mozilla Firefox extension.
However, it throws this error:
This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled.
After some researching i figured out:
1) Firefox extensions not supported by Firebase.
2) Adding of moz-extension:// doesn't work.
Here is some links to related questions:
Firebase Auth with Firefox Web Extension Add On
https://discourse.mozilla.org/t/moz-extension-protocol-is-not-accepted-by-firebase-any-workarounds/32570
Any workarounds at the moment? It has been one year since the problem was discovered... I need to use exactly Firebase for authentification, because it shares common DB.
Firebase does not support extension environments outside of Chrome currently, such as Firefox add-ons and Safari extensions.
You can view a full list of supported environments on this page.
There isn't any way to work around this issue, so for the time being, you can submit a feature request for Firebase support of other environments such as Firefox add-ons and Safari extensions here.

Google API Explorer deprecated for Endpoints APIs?

I have a REST API published to Google Endpoints and have been using the API Explorer to interact with it. When I accessed API Explorer this week I found this notice:
"This site is deprecated for Endpoints APIs. For exploring and testing Endpoints APIs, try the Cloud Endpoints Portal."
I can't find any other information such as when this service will be terminated. Anybody have a link or other information?
The APIs Explorer not going away so much as moving to Cloud Endpoints Portals. You still get an APIs Explorer there with all the same features, and more. It's just a newer format more specific to your API, with more detail and better navigation.
As mentioned on that page, you can try out the demo, including trying out your own API spec using the "Try your own API!" button.

Firebase dynamic links in UWP

So Firebase has these Dynamic links, which if you click in your Android / iPhone you get redirected to your app instead of the website. So when you want to invite your friends to join you in the app (game, group chat or whatever) you just share this link with them.
I was wondering if this was achievable with UWP. I watched a video about project Rome where they talk about AppUriHandlers which seem to do the job. HOWEVER they require you to have a json file at your web server root which would identify your app, saying "yea, this app is allowed and me are associated, open this app when someone launches this link".
The problem with that is that the Firebase dynamic link points to a google endpoint, e.g. https://aaxy2.app.goo.gl/?link=redirect_here and naturely there is going to be no json file just sitting there.
Is there some other way how to have users redirected to my app just via a link (it needs to be an http link because that's what the Android and iOS versions of the app will be using).
It's not going to be possible; for this exact reason. To ensure that web links aren't hijacked by third parties (for potentially malicious reasons), only the owner of a domain (or more accurately: the person/people with access to the storage where the domains points) can "approve" an app.
Update:
After actually doing my job and properly reading your question, I can give you a correct answer; sorry :/
Linking to UWP apps will work similarly to how it's described for iOS apps in the first section here:
You can do the iOS 8 way and support a uri scheme as described in the Windows docs here.
With the Anniversary Update you can also support AppUriHandlers by directing your users to a web link that will launch your app instead (as described in the Dynamic Links docs for iOS 9).
It looks like, however, that you need to register an iOS or Android app to get going, so that might give you some trouble.

Resources