-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.js
59 lines (57 loc) · 2.58 KB
/
main.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
((win, doc, nav) => {
const detectFeatures = (registration) => {
return {
'Offline Capabilities': 'caches' in win,
'Push Notifications': 'pushManager' in registration,
'Add to Home Screen': 'relList' in HTMLLinkElement.prototype &&
doc.createElement('link').relList.supports('manifest') &&
'onbeforeinstallprompt' in win,
'Background Sync': 'sync' in registration,
'Periodic Background Sync': 'periodicSync' in registration,
'Background Fetch': 'backgroundFetch' in registration,
'Navigation Preload': 'navigationPreload' in registration,
'Storage Estimation': 'storage' in nav && 'estimate' in nav.storage,
'Persistent Storage': 'storage' in nav && 'persist' in nav.storage,
'Web Share (Level 1)': 'share' in nav,
'Web Share (Level 2)': 'share' in nav && 'canShare' in nav,
'Media Session': 'mediaSession' in nav,
'Media Capabilities': 'mediaCapabilities' in nav,
'Device Memory': 'deviceMemory' in nav,
'Getting Installed Related Apps': 'getInstalledRelatedApps' in nav,
'Payment Request': 'PaymentRequest' in win,
'Payment Handler': 'paymentManager' in registration,
'Credential Management': 'credentials' in nav &&
'preventSilentAccess' in nav.credentials &&
('PasswordCredential' in win || 'FederatedCredential' in win),
};
};
const updateUserInterface = (pwaFeatures) => {
const fragment = doc.createDocumentFragment();
const featureRow = doc.getElementById('featureRow');
const featureCell = featureRow.content.querySelector('.feature');
const supportCell = featureRow.content.querySelector('.support');
for (const feature in pwaFeatures) {
if (!pwaFeatures.hasOwnProperty(feature)) {
continue;
}
featureCell.textContent = feature;
supportCell.textContent = pwaFeatures[feature] ? '✅' : '❌';
fragment.appendChild(doc.importNode(featureRow.content, true));
}
const placeholder = doc.getElementById('placeholder');
placeholder.parentNode.replaceChild(fragment, placeholder);
};
win.addEventListener('load', () => {
doc.getElementById('userAgent').textContent = nav.userAgent;
win.setTimeout(() => {
if ('serviceWorker' in nav) {
return nav.serviceWorker.register('sw.min.js')
.then((registration) => {
const pwaFeatures = detectFeatures(registration);
updateUserInterface(pwaFeatures);
});
}
updateUserInterface({'Service Workers Not Supported': false});
}, 500);
});
})(window, document, navigator);