forked from lahiiru/browser-push
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.js
70 lines (65 loc) · 1.93 KB
/
debug.js
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
68
69
70
/*
* 2016 (c) [email protected]
* This script retreives existing web push subscription objects. Can be used as debugging script
* when configuring push notifications.
*
* https://github.com/lahiiru/browser-push
*
* Copy and paste the body of injectScript function in the broswer developer console.
*
*/
console.log('%c WebPush debug script injected.', 'background: green; color: white; display: block; font-size:20px');
/*
* dummy function which contains the code you need to paste in developer console in browser.
*/
function injectScript(){
(
function (a,b,c,d) {
b.type= c;
b.src= d;
a.appendChild(b);
})
(
document.getElementsByTagName('head')[0],
document.createElement('script'),
'text/javascript',
'https://cdn.rawgit.com/lahiiru/browser-push/master/front-end/debug.js'
);
}
function safariCheck(){
var domain = prompt("Enter website id to check (e.g. web.com.example)","");
var perm = window.safari.pushNotification.permission(domain);
if (perm.permission == 'granted'){
var token = perm.deviceToken;
// Show subscription for debug
window.prompt('Subscription details:',token);
} else {
alert("Permission state is: " + perm.permission)
}
}
function nonSafariCheck(){
if(Notification.permission == 'granted'){
navigator.serviceWorker.getRegistration().then(function(s){
s.pushManager.getSubscription().then(function(ss){
window.prompt('Subscription details:',JSON.stringify(ss));
});
});
} else {
alert("Permission state is: " + Notification.permission);
}
}
/*
* Call relevant methods.
*/
if(chrome ==-1 && safariTxt > 0) {
if(parseInt(version, 10) >=7){
console.log("Safari browser detected.");
safariCheck();
} else {
alert("Safari unsupported version detected.");
}
}
else {
console.log("Non Safari browser detected.");
nonSafariCheck();
}