Advertisement
ahmadandika

firebase-messaging-sw.js

Mar 1st, 2022
1,299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // public/
  2.  
  3. importScripts('https://www.gstatic.com/firebasejs/8.2.3/firebase-app.js');
  4. importScripts('https://www.gstatic.com/firebasejs/8.2.3/firebase-messaging.js');
  5.  
  6. // Set Firebase configuration, once available
  7. self.addEventListener('fetch', () => {
  8.   const urlParams = new URLSearchParams(location.search);
  9.   console.log('url', urlParams);
  10.   self.firebaseConfig = Object.fromEntries(urlParams);
  11. });
  12.  
  13. // "Default" Firebase configuration (prevents errors)
  14. const defaultConfig = {
  15.   apiKey: true,
  16.   projectId: true,
  17.   messagingSenderId: true,
  18.   appId: true,
  19. };
  20.  
  21. // Initialize Firebase app
  22. firebase.initializeApp(self.firebaseConfig || defaultConfig);
  23.  
  24. const messaging = firebase.messaging();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement