mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-19 09:24:51 +00:00
feature: client: self signed certs on Chrome (#393)
This commit is contained in:
parent
895d19a153
commit
ef6088531a
2 changed files with 28 additions and 1 deletions
|
|
@ -1,5 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const tryToCatch = require('try-to-catch');
|
||||
|
||||
module.exports.registerSW = registerSW;
|
||||
module.exports.unregisterSW = unregisterSW;
|
||||
|
||||
|
|
@ -17,7 +19,14 @@ async function registerSW(prefix) {
|
|||
if (!isHTTPS && !isLocalhost)
|
||||
return;
|
||||
|
||||
return await navigator.serviceWorker.register(`${prefix}/sw.js`);
|
||||
const {serviceWorker} = navigator;
|
||||
const register = serviceWorker.register.bind(serviceWorker);
|
||||
const [e, sw] = await tryToCatch(register,`${prefix}/sw.js`);
|
||||
|
||||
if (e)
|
||||
return null;
|
||||
|
||||
return sw;
|
||||
}
|
||||
|
||||
async function unregisterSW(prefix) {
|
||||
|
|
|
|||
|
|
@ -70,6 +70,24 @@ test('sw: register: registerSW: http', async (t, {location, navigator}) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('sw: register: registerSW: https self-signed', async (t, {location, navigator}) => {
|
||||
Object.assign(location, {
|
||||
protocol: 'https',
|
||||
hostname: 'self-signed.badssl.com',
|
||||
});
|
||||
|
||||
const {register} = navigator.serviceWorker;
|
||||
register.throws(Error('Cannot register service worker!'));
|
||||
|
||||
const {registerSW} = reRequire('./register');
|
||||
|
||||
const result = await registerSW();
|
||||
|
||||
t.notOk(result, 'should not throw');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('sw: register: registerSW', async (t, {location, navigator}) => {
|
||||
location.hostname = 'localhost';
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue