mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
29 lines
648 B
JavaScript
29 lines
648 B
JavaScript
'use strict';
|
|
|
|
module.exports.registerSW = registerSW;
|
|
module.exports.unregisterSW = unregisterSW;
|
|
|
|
const noop = () => {};
|
|
|
|
async function registerSW(prefix) {
|
|
prefix = prefix ? `/${prefix}/` : `/`;
|
|
|
|
if (!navigator.serviceWorker)
|
|
return;
|
|
|
|
const isHTTPS = location.protocol === 'https:';
|
|
const isLocalhost = location.hostname === 'localhost';
|
|
|
|
if (!isHTTPS && !isLocalhost)
|
|
return {
|
|
addEventListener: noop,
|
|
};
|
|
|
|
return navigator.serviceWorker.register(`${prefix}sw.js`);
|
|
}
|
|
|
|
async function unregisterSW() {
|
|
const reg = await registerSW();
|
|
return reg.unregister();
|
|
}
|
|
|