-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
204 lines (190 loc) · 5.96 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="manifest" href="/manifest.json">
<!-- <link rel="shortcut icon" href="/favicon.ico"> -->
<link rel="icon" href="/img/ico.png" type="image/x-icon">
<!-- <link href="/build/mobile.css" rel="stylesheet"> -->
<!-- <script src="/js/promise.js" defer></script> -->
<!-- <script src="/js/react.js" defer></script> -->
<!-- <script src="/js/react-dom.js" defer></script> -->
<!-- <script src="https://cdn.bootcss.com/babel-polyfill/7.0.0-beta.42/polyfill.min.js" defer></script> -->
<!-- <script src="https://unpkg.com/react/umd/react.development.js" defer></script> -->
<script src="https://cdn.jsdelivr.net/npm/react/umd/react.development.js" defer></script>
<!-- <script src="https://unpkg.com/[email protected]/umd/react.development.js" defer></script> -->
<!-- <script src="https://unpkg.com/react-dom/umd/react-dom.development.js" defer></script> -->
<script src="https://cdn.jsdelivr.net/npm/react-dom/umd/react-dom.development.js" defer></script>
<!-- <script src="https://cdn.jsdelivr.net/gh/axios/axios/dist/axios.js" defer></script> -->
<!-- <script src="/build/mobile.js" defer></script> -->
<script>
if (navigator.userAgent.toLowerCase().indexOf('mobile') === -1) {
document.writeln('<link href="/build/main.css" rel="stylesheet">')
document.writeln('<script src="/build/main.js" defer><\/script>')
} else {
document.writeln('<link href="/build/mobile.css" rel="stylesheet">')
document.writeln('<script src="/build/mobile.js" defer><\/script>')
}
</script>
<script src="/build/runtime.js" defer></script>
<script>
function report(url, body) {
return fetch(url, {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/json'
}),
body: JSON.stringify(body),
}).catch(e => {
console.error(e);
});
}
function onerror(m, f, l, c, e) {
// console.error(m);
var data = {
m: m,
f: f,
l: l,
c: c
};
if (m instanceof ErrorEvent) {
var event = m;
data.m = event.message;
data.f = event.filename;
data.l = event.lineno;
data.c = event.colno;
e = event.error;
} else if (m instanceof Event) {
var event = m;
data.m = 'load error';
data.baseURI = event.target.baseURI;
data.outerHTML = event.target.outerHTML;
data.src = event.target.src;
}
if (e && e.stack) {
data.e = e.stack;
}
console.log(data);
report('/error', {
message: 'onerror',
error: data
});
}
window.addEventListener('error', onerror, true);
window.addEventListener("unhandledrejection", function(e) {
console.log(e);
report('/error', {
message: 'unhandledrejection',
error: e
});
});
</script>
<script>
if (navigator.serviceWorker && navigator.serviceWorker.register) {
navigator.serviceWorker.register('/sw.js').then(function(registration) {
console.log(registration);
if (window.PushManager) {
registration.pushManager.getSubscription().then(subscription => {
// 如果用户没有订阅
if (!subscription) {
subscribeUser(registration);
} else {
console.log("已经订阅:", subscription);
return report('/addSubscription', subscription);
}
});
} else {
report('/error', {
message: '不支持消息推送',
userAgent: window.navigator.userAgent,
});
}
function subscribeUser(registration) {
var publicKey = "BGqo-JssZAJ02xFMA4mZuLZi19JDVKWwpJmnC2npe7c1ma7HSjX0_qw8JrOYaVR15iM7O44qs8kXh1iL51em44o";
var applicationServerKey = urlBase64ToUint8Array(publicKey);
registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: applicationServerKey
})
// 用户同意
.then(function(subscription) {
console.log('用户订阅subscription:', subscription);
return report('/addSubscription', subscription);
})
// 用户不同意或者生成失败
.catch(function(err) {
console.log('订阅推送失败: ', err);
report('/error', {
message: '订阅推送失败',
error: err
});
});
}
function urlBase64ToUint8Array(base64String) {
var padding = '='.repeat((4 - base64String.length % 4) % 4);
var base64 = (base64String + padding)
.replace(/\-/g, '+')
.replace(/_/g, '/');
var rawData = window.atob(base64);
var outputArray = new Uint8Array(rawData.length);
for (var i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
return outputArray;
}
}).catch(function(error) {
report('/error', {
message: 'serviceWorker注册报错',
err: error,
userAgent: window.navigator.userAgent,
});
console.error(error)
});
} else {
report('/error', {
message: '不支持serviceWorker',
userAgent: window.navigator.userAgent,
});
}
</script>
<!-- <script>
var observer = new PerformanceObserver(function(list, obj) {
var entries = list.getEntries();
console.log("PerformanceObserver", entries, list, obj);
});
//调用observer对象的observe()方法
observer.observe({
entryTypes: [
"frame",
"navigation",
// "resource",
// "mark",
"measure",
"paint",
]
});
</script> -->
<!-- <script src="https://www.gstatic.com/firebasejs/5.4.2/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyCcdF6B145_La4F61nsJMOCSBRsBHmEbvs",
authDomain: "push-dac91.firebaseapp.com",
databaseURL: "https://push-dac91.firebaseio.com",
projectId: "push-dac91",
storageBucket: "push-dac91.appspot.com",
messagingSenderId: "568776137202"
};
firebase.initializeApp(config);
</script> -->
<title>Demo测试平台</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root">${html}</div>
</body>
</html>