-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
35 lines (30 loc) · 811 Bytes
/
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>bg notification test</title>
</head>
<body>
<button onclick="sendMessage('start')">Start Listen</button>
<button onclick="sendMessage('stop')">Stop Listen</button>
<script>
let se;
navigator.serviceWorker.register('/sw.js').then(data => {
se = data.active;
console.log('se ready!');
});
function sendMessage(message) {
if (!se) {
console.log('sw is not ready yet');
return;
}
se.postMessage(message);
}
Notification.requestPermission().then(registration => {
console.log(registration);
});
</script>
</body>
</html>