-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
59 lines (50 loc) · 2.23 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FCM</title>
</head>
<body>
<h1>Firebase Push Notification</h1>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js";
import { getMessaging, getToken } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-messaging.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyD4ZJYj51aGktzHM7YCvOGXJCb_sqER-IA",
authDomain: "hello-notif-63ad4.firebaseapp.com",
projectId: "hello-notif-63ad4",
storageBucket: "hello-notif-63ad4.appspot.com",
messagingSenderId: "852811610870",
appId: "1:852811610870:web:6d6cc83137a8e6a026cad7",
measurementId: "G-YERW0QQJ5T"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const messaging = getMessaging(app);
navigator.serviceWorker.register("sw.js").then(registration => {
getToken(messaging, {
serviceWorkerRegistration: registration,
vapidKey: 'BN3Q2xi4T3SaR57-LPINax16NGaBPrZMOMlo-R6HlbxGEl7C7gIsXDN2ymGcUW2dmp2pYKC0uTuuXkeKpr36sng' }).then((currentToken) => {
if (currentToken) {
console.log("Token is: "+currentToken);
// Send the token to your server and update the UI if necessary
// ...
} else {
// Show permission request UI
console.log('No registration token available. Request permission to generate one.');
// ...
}
}).catch((err) => {
console.log('An error occurred while retrieving token. ', err);
// ...
});
});
</script>
</body>
</html>