Replies: 25 comments 23 replies
-
Hey @markgoho! You can do that, but I'm not certain it's a good idea. The ngsw is not meant to work with other SW libraries and it also works differently than your typical Service Worker. Trying to munge the two together could result in unpredictable results and that's not really good with something as powerful as a Service Worker. Before we could recommend it we would need to see if it is a good idea, and at my early research suggests that it is not. The long term solution is to have the ngsw use Firebase Messaging for push notifications. This is something I've spoken with the Angular team about and they are supportive of doing it. In the meantime I recommend using Workboxjs with Firebase Messaging. It's really easy and it's a proven path. |
Beta Was this translation helpful? Give feedback.
-
Thank you for this input @davideast! I'm not sure if your recommendation against the concatenation method includes the second option as well to use For a current workaround are you suggesting to scrap the ngsw (via Finally, I haven't seen an issue filed in the Angular repo for this specific issue (although this issue seems very similar). I'm not 100% sure what the actual issue is that prevents us from using FCM. Since you mentioned speaking to the core team about the issue, what do you suggest as far as creating an issue to track this need for a better FCM service worker integration? I greatly appreciate the guidance here - and I'm more than willing to do the work to create the documentation for whatever solution we gather around. I just want to make sure I'm not spending hours researching a solution that someone already has in production. |
Beta Was this translation helpful? Give feedback.
-
🤯 to my amazement, This is much better than just concatenating files and also preserves the angular worker - are there issues I'm not aware of @davideast ? |
Beta Was this translation helpful? Give feedback.
-
It looks like you have to That seems....sub-optimal, but maybe I'm missing something. |
Beta Was this translation helpful? Give feedback.
-
Can you use
|
Beta Was this translation helpful? Give feedback.
-
I am able to use the way @codediodeio did to hook up firebase and default angular ngsw-worker by do following. The foreground also receive notifications like @codediodeio point out, haven't test the background app yet. I thought the app.module.ts:
app.component.ts:
messaging.service.ts:
|
Beta Was this translation helpful? Give feedback.
-
@zhangxin511 Is there something missing perhaps? |
Beta Was this translation helpful? Give feedback.
-
@SauceCode84 I think it may because you didn't initialize the firebase app properly in your module. Can you show how you initialize it? I think you might miss the messaging module? For me, I end up not using angular dependency injection since I used dynamic firebase configurations that got from api, this is what the partial code looks like: The component using the firebase messaging: |
Beta Was this translation helpful? Give feedback.
-
I'm trying to call a Firebase Function and I'm getting this error:
searching about this Error Message it seems related to the Service Worker BTW, a smooth integration with the |
Beta Was this translation helpful? Give feedback.
-
This may be a dumb question, but can we use the method described here to implement FCM with the Angular Service Worker? |
Beta Was this translation helpful? Give feedback.
-
@wooldridgetm That if app active, this thread is mainly talk about notifications working with ngsw, service worker, so the app can get notifications when it is not active or closed. |
Beta Was this translation helpful? Give feedback.
-
@zhangxin511 Just so I understand you...you're saying this method doesn't allow notifications when the app is closed or isn't active? |
Beta Was this translation helpful? Give feedback.
-
@wooldridgetm Sorry I may miss understand your question. If you are asking if we can not use FCM but use the method you mentioned, yes you can.
I end up using some customized logic to overwrites the default angular service worker js file and made the the off-load notification works (not for safari, nor ios, which is another story). |
Beta Was this translation helpful? Give feedback.
-
Ah, yes, I understand now. Thanks! |
Beta Was this translation helpful? Give feedback.
-
@SauceCode84 @wooldridgetm @matheo I created a post about this if you are still interested. Along with the demo repo here |
Beta Was this translation helpful? Give feedback.
-
This issue in the Angular repo requested by the documentation appears to have been created here: angular/angular#34352 |
Beta Was this translation helpful? Give feedback.
-
@zhangxin511 I have been looking at implementing your method and fired up your demo. it all works except for subscribing to messages and notificationClicks from SwPush. Did you manage to get these two working? |
Beta Was this translation helpful? Give feedback.
-
@bevbomb I am not sure what exactly you did, but if you follow the post, should have worked for subscribing to messages and notificationClicks from SwPush. Did you check your angular versions? There is a picture for the app there:
|
Beta Was this translation helpful? Give feedback.
-
@zhangxin511 i managed to get it working. I declared a local variable of firebase.messaging() to use In place of calling the instance each time and it worked after that. I’m not sure how that would have affected it. |
Beta Was this translation helpful? Give feedback.
-
FYI we now support |
Beta Was this translation helpful? Give feedback.
-
Very pleased with @zhangxin511 's solution as he published under Kabbage Engineering blog. Using the new Snippets of code:
|
Beta Was this translation helpful? Give feedback.
-
Hello all, can anyone tell me why AngularFireMessaging is not compatible with the Angular Service Worker and what's the impact of having both working simultaneously? |
Beta Was this translation helpful? Give feedback.
-
Hi all, Are there any news regarding documentation for FCM with ngsw. I feel a bit lost as I see a lot of scattered information about what needs to be done to implement FCM, and was hoping someone could point me to a stackblitz or an article explaining all the steps in detail? P.S. Sorry if this is too random, I am not a very experienced developer :/ |
Beta Was this translation helpful? Give feedback.
-
Hey just wondering has there been any updates on this? Above, on Aug 30th 2021 jamesdanies says to just use v7 compat, is it ok to use the new non compat version now? |
Beta Was this translation helpful? Give feedback.
-
Hey, do we have any news on this? |
Beta Was this translation helpful? Give feedback.
-
So there's this:
This kind of leads folks to believe that there isn't a solution to use FCM with the Angular Service Worker. However, some light searching has revealed a few workarounds to use both. I'm hoping we could unify around one solution and then add it to the docs to help others that might just give up.
Concatenate the ngsw and FCM sw files
This one is Jeff Delaney's (@codediodeio) solution posted on AngularFirebase from April 2018.
Basically, create a new service worker file and, sometime post-build, concatenate the FCM file and ngsw file together and reference this combined file in the app.module.ts file where the service worker is registered.
Use a native firebase method
useServiceWorker()
to use the ngsw in place of the FCM swThis one has popped up in a number of places, most notably on StackOverflow in a question that Michael Bleigh (@mbleigh) from Firebase answered.
Here, from what I gather (particularly from this SO answer) you can wait for the ngsw to register and then take that registered worker and pass it into useServiceWorker() and FCM will use that worker.
I haven't implemented either solution yet. I'm just trying to put some ideas out here for discussion. I'll follow up with some pros and cons of each as I'm able to try each solution. What do you guys think? Have experience with either one?
Beta Was this translation helpful? Give feedback.
All reactions