DEV Community

Cover image for Angular 8 + Firebase Cloud Messaging Push Notifications

Angular 8 + Firebase Cloud Messaging Push Notifications

Mayur Kadam on January 25, 2020

Are you looking for push notification which is normally you seen in ANDROID application or IOS application which is basically giving popup on your ...
Collapse
 
manishgarg0 profile image
manishgarg0

Hi I am getting below mentioned error.

Unable to get permission to notify. TypeError: Failed to execute 'subscribe' on 'PushManager': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'

Collapse
 
chaawlaapooja profile image
chaawlaapooja

I am getting the same error

Collapse
 
mayurkadampro profile image
Mayur Kadam

Check for version on firebase and also check notification permission on ur browser

Collapse
 
anthonyspault profile image
Anthony Spault

I'm facing the same issue. My firebase was previously in 7.7.0. After update to 7.8.2, still getting the error. It was working before so i'm a bit confused

Collapse
 
mayurkadampro profile image
Mayur Kadam

Check for version on firebase and also check notification permission on ur browser

Collapse
 
manishgarg0 profile image
manishgarg0

version is 7.8.1 and all the browser permissions are allowed. still, I am facing the same issue.

Collapse
 
vishtalk profile image
vishtalk

mayur bhau mala ek error yetoy yaar help kr na bhau..

ERROR in src/app/services/messaging.service.ts:10:31 - error TS2339: Property 'messaging' does not exist on type 'AngularFireMessaging'

code ->

this.angularFireMessaging.messaging.subscribe(
(_messaging) => {
_messaging.onMessage = _messaging.onMessage.bind(_messaging);
_messaging.onTokenRefresh = _messaging.onTokenRefresh.bind(_messaging);
}
)

1st line of code bg

Collapse
 
mayurkadampro profile image
Mayur Kadam

Check version of install angular fire module

Collapse
 
ppradhan9 profile image
Pradipta Pradhan

stackoverflow.com/questions/612442...
firebase version 5.1.1 is compatible

Collapse
 
prasadkhegade profile image
prasadkhegade

Hello Mayur,

Getting following error

ERROR in src/app/service/messaging.service.ts:10:35 - error TS2339: Property 'messaging' does not exist on type 'AngularFireMessaging'.

this.angularFireMessaging.messaging.subscribe(

Firebase version: 7.6.0
Angular Version: 9

Collapse
 
miqueasgutierrez profile image
miqueasgutierrez

Another simple way to integrate Push notifications in the Javascript platform is by integrating the INDIGITALL Service, it has been developed with the latest technology to guarantee maximum effectiveness and simplify the process of creating and sending Notifications with animated image, Segmented, Geolocated and many functions. .
Here you can see the steps for its integration for any Javascript platform:docs.indigitall.com/es/sdk/webpush...

Collapse
 
adibw profile image
Adib Ouechani

Hi, I have a dashboard project with angular 8 and my friend have a mobile application project with Kotlin.
I want to send a notification from my dashboard to her mobile application.
My question is how can I send the notification? Should I do the same as the tutorial?

Collapse
 
ahmedtgp profile image
Ahmed Nasser

Unable to get permission to notify. FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('localhost:4200/firebase-cloud-mess...) with script ('localhost:4200/firebase-messaging-... A bad HTTP response code (404) was received when fetching the script. (messaging/failed-service-worker-registration).
at WindowController. (localhost:4200/firebase-messaging....)
at step (localhost:4200/vendor.js:10112:23)
at Object.throw (localhost:4200/vendor.js:10093:53)
at rejected (localhost:4200/vendor.js:10084:65)
at ZoneDelegate.invoke (localhost:4200/polyfills.js:9743:30)
at Object.onInvoke (localhost:4200/vendor.js:161262:33)
at ZoneDelegate.invoke (localhost:4200/polyfills.js:9742:36)
at Zone.run (localhost:4200/polyfills.js:9502:47)
at localhost:4200/polyfills.js:10236:40
at ZoneDelegate.invokeTask (localhost:4200/polyfills.js:9778:35)

Collapse
 
tharindu960490240 profile image
Tharindu

zone.js:699 Unhandled Promise rejection: this._next is not a function ; Zone: ; Task: ServiceWorkerContainer.addEventListener:message ; Value: TypeError: this._next is not a function
at WindowController.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next as onMessageCallback
at WindowController. (index.esm.js:1067)
at step (tslib.es6.js:100)
at Object.next (tslib.es6.js:81)
at tslib.es6.js:74
at new ZoneAwarePromise (zone.js:915)
at __awaiter (tslib.es6.js:70)
at WindowController.push../node_modules/@firebase/messaging/dist/index.esm.js.WindowController.messageEventListener (index.esm.js:1056)
at ServiceWorkerContainer. (index.esm.js:890)
at ZoneDelegate.invokeTask (zone.js:431) TypeError: this._next is not a function
at WindowController.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next as onMessageCallback
at WindowController. (localhost:4200/firebase-messaging....)
at step (localhost:4200/vendor.js:180014:23)
at Object.next (localhost:4200/vendor.js:179995:53)
at localhost:4200/vendor.js:179988:71
at new ZoneAwarePromise (localhost:4200/polyfills.js:4720:33)
at __awaiter (localhost:4200/vendor.js:179984:12)
at WindowController.push../node_modules/@firebase/messaging/dist/index.esm.js.WindowController.messageEventListener (localhost:4200/firebase-messaging....)
at ServiceWorkerContainer. (localhost:4200/firebase-messaging....)
at ZoneDelegate.invokeTask (localhost:4200/polyfills.js:4236:35)

forground error please help

"@angular/fire": "^5.4.2",
"firebase": "^7.14.2",

Collapse
 
carlossaldivia1 profile image
Carlos Saldivia

Good morning, thanks for the tutorial, it has helped me a lot in my project, however I have a question, how can I get to "get" the response of the firebase service from any page?

What happens is that my project has several pages, even though I declare the objects in the "AppComponent" as it is in your example, when I pass to another screen the service response is stopped "listening".

How could I solve this so that I am always "listening" to the service from any page of my project?

Collapse
 
mayurkadampro profile image
Mayur Kadam

right now in current market if you look for an alternative to firebase then look into aws they are also providing the same services

Collapse
 
m98 profile image
Kermani

Thanks for the good article.

Does FireBase SDK itself look for firebase-messaging-sw.js file? Don't we need to import it anywhere on page or manifest? (except importing it in Angular.json)

Collapse
 
inshaf profile image
inshaf

Thanks alot for wonderful tutorial. I have implemented FCM on my Angular web app. I can receive ONLY the background notification ( when app is not active ), Im not sure what I have missed

Collapse
 
karthik11788 profile image
Karthik

it is working perfectly in localhost(both foreground and background)
but in https:// only working the background notification. No console errors are showing there

Collapse
 
mayurkadampro profile image
Mayur Kadam

Check out video tutorial which shown in this post bcoz i solve the same problem in that video

Collapse
 
kazimashry profile image
Kazi Nur Alam Mashry

I'm getting this error. Can you please help me?
Unable to get permission to notify. FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('localhost:4200/firebase-cloud-mess...) with script ('localhost:4200/firebase-messaging-... A bad HTTP response code (404) was received when fetching the script. (messaging/failed-service-worker-registration).

Collapse
 
jsanz1209 profile image
jsanz1209

Hi Mayur, this doesn't work when browser is closed, in other case, work like a charm.

Collapse
 
mayurkadampro profile image
Mayur Kadam

Yes agreeed bcoz service is running on browser so open browser is the main condition

Collapse
 
karthik11788 profile image
Karthik

Hi @mayur thanks for the FCM,
it is working perfectly in localhost(both foreground and background)
but in https:// only working the background notification. No console errors are showing there

Collapse
 
mukherjee96 profile image
Aritra Mukherjee

Great tutorial. Very detailed. One question - isn't it better to install Firebase Messaging via NPM instead of importing the scripts?

Collapse
 
mayurkadampro profile image
Mayur Kadam

Yes we will install firbase via npm and in this post i show the both of them and for the push notification we req both bcoz we are importing firebase script in service worker so it will run in background and one is install via npm which is going to use in forground...
See the video tutorial for more clear understanding

Collapse
 
nids8953 profile image
nids8953 • Edited

Property 'messaging' does not exist on type 'AngularFireMessaging'.ts(2339)

kindly help

"@angular/fire": "^6.0.2",
"firebase": "^7.18.0",

"@angular/core": "~9.1.11",

Collapse
 
muhammadawaisshaikh profile image
Muhammad Awais

constructor(
private angularFireMessaging: AngularFireMessaging,
private checkLoginService: CheckLoginService,
) {
this.angularFireMessaging.messages.subscribe(
(_messaging: AngularFireMessaging) => {
_messaging.onMessage = _messaging.onMessage.bind(_messaging);
_messaging.onTokenRefresh = _messaging.onTokenRefresh.bind(_messaging);
}
)
}

Collapse
 
dhandalchetan profile image
DhandalChetan

Great! works perfectly

Is there some way to customize the browser icon in notifications

Collapse
 
mafeidev profile image
mafei

stackoverflow.com/a/66873650/12553450
this is the answer. it's working.

Collapse
 
suzette2828 profile image
suzette2828

Hi it displays the notification in the index but there are no notification popup shows.