-
Notifications
You must be signed in to change notification settings - Fork 4
/
permissions.html
67 lines (66 loc) · 2.31 KB
/
permissions.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
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html>
<head>
<title>Permissions API test page</title>
<link rel='manifest' href='manifest.json'>
</head>
<body>
<h3>Permissions</h3>
<div><b>Geolocation:</b> <span id='geolocation'></span></div>
<div><b>Notifications:</b> <span id='notifications'></span></div>
<div><b>Midi:</b> <span id='midi'></span></div>
<div><b>Midi SysEx:</b> <span id='midi-sysex'></span></div>
<div><b>Push Notifications:</b> <span id='push-notifications'></span></div>
<fieldset>
<legend>Requests</legend>
<button onclick="navigator.geolocation.getCurrentPosition(function(){});">Geolocation</button>
<button onclick="Notification.requestPermission();">Notifications</button>
<button onclick="navigator.requestMIDIAccess({sysex:true});">Midi SysEx</button>
<button onclick="requestPushPermission();">Push Notifications</button>
</fieldset>
</body>
<script>
function requestPushPermission() {
navigator.serviceWorker.register('/sandbox/sw-focus.js', {
scope: '/sandbox/'
}).then(function(reg) {
return reg.pushManager.subscribe({userVisibleOnly: true});
}).then(function(reg) {
console.log('push reg', reg);
});
}
</script>
<script>
function updatePermission(name, state) {
document.getElementById(name).textContent = state;
}
function init() {
navigator.permissions.query({name:'geolocation'}).then(function(p) {
var update = function() { updatePermission('geolocation', p.state); };
update();
p.onchange = update;
});
navigator.permissions.query({name:'notifications'}).then(function(p) {
var update = function() { updatePermission('notifications', p.state); };
update();
p.onchange = update;
});
navigator.permissions.query({name:'midi', sysex:false}).then(function(p) {
var update = function() { updatePermission('midi', p.state); };
update();
p.onchange = update;
});
navigator.permissions.query({name:'midi', sysex:true}).then(function(p) {
var update = function() { updatePermission('midi-sysex', p.state); };
update();
p.onchange = update;
});
navigator.permissions.query({name:'push', userVisibleOnly:true}).then(function(p) {
var update = function() { updatePermission('push-notifications', p.state); };
update();
p.onchange = update;
});
}
init();
</script>
</html>