DOMException: Failed to register a ServiceWorker for scope -- when using self signed certificates on Chrome
cintolas opened this issue · 4 comments
Chrome throws a DOMException when using a self signed certificate and NOT connecting via localhost.
This causes all the popup menus to fail
Chrome requires that Service Workers have valid certificates.
Firefox/Safari do not require Valid certificates, only HTTPS
The issue arises in client/sw/register.js
async function registerSW(prefix) {
if (!navigator.serviceWorker)
return;
const isHTTPS = location.protocol === 'https:';
const isLocalhost = location.hostname === 'localhost';
if (!isHTTPS && !isLocalhost)
return;
return await navigator.serviceWorker.register(`${prefix}/sw.js`);
}
It seems that you could put the following line in a try/catch block to fix it (ie disable service worker if registration fails)
return await navigator.serviceWorker.register(
${prefix}/sw.js);
-
Version (
cloudcmd -v
):
v16.14.1 -
Node Version
node -v
:
17.9.0 -
OS (
uname -a
on Linux):
Linux fedora 5.11.12-300.fc34.aarch64 #1 SMP Wed Apr 7 16:12:21 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux -
Browser name/version:
Chrome Version 112.0.5615.137 (Official Build) (arm64) -
Used Command Line Parameters:
Using as an express app -
Changed Config:
let prefix = argv.base + '/user/file-manager';
const socket = new Server(server, {
path: `${prefix}/socket.io`,
});
const config = {
name: 'File Manager',
contact: false,
configDialog: false,
root: expandenv(argv.rootDir),
console: false
};
const filePicker = {
data: {
FilePicker: {
key: 'key',
},
},
};
// override option from json/modules.json
const modules = {
filePicker,
};
const {
createConfigManager,
configPath,
} = cloudcmd;
const configManager = createConfigManager({
configPath,
});
app.use(prefix, cloudcmd({
socket,
config,
modules,
configManager
}));
Are you up for a PR? Why not using letsencrypt?
try-to-catch
can be used for this purpose.
I can make a PR if needed. Do you have any documentation on how to build it?
We use cloudcmd on private networks. During the testing phase we create self signed certs to speed up validation. In production real certs are used
npm run build:start
Lines 26 to 27 in bd7dfd0
Landed in Cloud Commander v16.15.0 🎉. Is it works for you?