Fix PWA callback assignment and error handling
This commit is contained in:
34
misc/dist/html/editor.html
vendored
34
misc/dist/html/editor.html
vendored
@ -363,24 +363,28 @@ window.addEventListener('load', () => {
|
||||
btn.style.display = '';
|
||||
}
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('service.worker.js').then(function (reg) {
|
||||
if (reg.waiting) {
|
||||
notifyUpdate(reg.waiting);
|
||||
}
|
||||
reg.addEventListener('updatefound', function () {
|
||||
const update = reg.installing;
|
||||
update.addEventListener('statechange', function () {
|
||||
if (update.state === 'installed') {
|
||||
// It's a new install, claim and perform aggressive caching.
|
||||
if (!reg.active) {
|
||||
update.postMessage('claim');
|
||||
} else {
|
||||
notifyUpdate(update);
|
||||
try {
|
||||
navigator.serviceWorker.register('service.worker.js').then(function (reg) {
|
||||
if (reg.waiting) {
|
||||
notifyUpdate(reg.waiting);
|
||||
}
|
||||
reg.addEventListener('updatefound', function () {
|
||||
const update = reg.installing;
|
||||
update.addEventListener('statechange', function () {
|
||||
if (update.state === 'installed') {
|
||||
// It's a new install, claim and perform aggressive caching.
|
||||
if (!reg.active) {
|
||||
update.postMessage('claim');
|
||||
} else {
|
||||
notifyUpdate(update);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Error while registering service worker:', e);
|
||||
}
|
||||
}
|
||||
|
||||
const missing = Engine.getMissingFeatures({
|
||||
|
||||
8
misc/dist/html/full-size.html
vendored
8
misc/dist/html/full-size.html
vendored
@ -152,9 +152,15 @@ const engine = new Engine(GODOT_CONFIG);
|
||||
|
||||
if (missing.length !== 0) {
|
||||
if (GODOT_CONFIG['serviceWorker'] && GODOT_CONFIG['ensureCrossOriginIsolationHeaders'] && 'serviceWorker' in navigator) {
|
||||
let serviceWorkerRegistrationPromise;
|
||||
try {
|
||||
serviceWorkerRegistrationPromise = navigator.serviceWorker.getRegistration();
|
||||
} catch (err) {
|
||||
serviceWorkerRegistrationPromise = Promise.reject(new Error('Service worker registration failed.'));
|
||||
}
|
||||
// There's a chance that installing the service worker would fix the issue
|
||||
Promise.race([
|
||||
navigator.serviceWorker.getRegistration().then((registration) => {
|
||||
serviceWorkerRegistrationPromise.then((registration) => {
|
||||
if (registration != null) {
|
||||
return Promise.reject(new Error('Service worker already exists.'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user