Created
          April 26, 2021 15:40 
        
      - 
      
 - 
        
Save kenng/ab2b7e587e25a89fe2f6beb74a7f1a27 to your computer and use it in GitHub Desktop.  
    web push 03
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | importScripts("https://www.gstatic.com/firebasejs/7.16.1/firebase-app.js"); | |
| importScripts( | |
| "https://www.gstatic.com/firebasejs/7.16.1/firebase-messaging.js", | |
| ); | |
| // For an optimal experience using Cloud Messaging, also add the Firebase SDK for Analytics. | |
| importScripts( | |
| "https://www.gstatic.com/firebasejs/7.16.1/firebase-analytics.js", | |
| ); | |
| // Initialize the Firebase app in the service worker by passing in the | |
| // messagingSenderId. | |
| firebase.initializeApp({ | |
| messagingSenderId: "YOUR-SENDER-ID", | |
| apiKey: "YOUR_API_KEY", | |
| projectId: "YOUR_PROJECT_ID", | |
| appId: "YOUR_APP_ID", | |
| }); | |
| // Retrieve an instance of Firebase Messaging so that it can handle background | |
| // messages. | |
| const messaging = firebase.messaging(); | |
| messaging.setBackgroundMessageHandler(function(payload) { | |
| console.log( | |
| "[firebase-messaging-sw.js] Received background message ", | |
| payload, | |
| ); | |
| // Customize notification here | |
| const notificationTitle = "Background Message Title"; | |
| const notificationOptions = { | |
| body: "Background Message body.", | |
| icon: "/itwonders-web-logo.png", | |
| }; | |
| return self.registration.showNotification( | |
| notificationTitle, | |
| notificationOptions, | |
| ); | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment