Skip to content

Firebase Messaging Service Worker #447

Discussion options

You must be logged in to vote

Found an old thread that answers this question:
#156

Custom service worker:

import { firebaseConfig } from '../src/firebase/FirebaseConfig';
import { getMessaging, onBackgroundMessage } from 'firebase/messaging/sw';
import { initializeApp } from 'firebase/app';

// get type file from: https://github.com/shadowwalker/next-pwa/blob/master/examples/custom-ts-worker/types/service-worker.d.ts
let self: ServiceWorkerGlobalScope;

const firebase = initializeApp(firebaseConfig);

const messaging = getMessaging(firebase);

onBackgroundMessage(messaging, async ({ notification }) => {
  console.log(
    '[firebase-messaging-sw.js] Received background message ',
    notification,
  );

  await self.r…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by bruceharrison1984
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant