[DEBUG] Investigate Service Worker issues (#3274)
This commit is contained in:
parent
f8825e5e5e
commit
f833c39f62
@ -1,4 +1,3 @@
|
||||
import { DEBUG } from './config';
|
||||
import { respondForProgressive } from './serviceWorker/progressive';
|
||||
import { respondForDownload } from './serviceWorker/download';
|
||||
import { respondWithCache, clearAssetCache, respondWithCacheNetworkFirst } from './serviceWorker/assetCache';
|
||||
@ -17,8 +16,10 @@ const RE_NETWORK_FIRST_ASSETS = /\.(wasm|html)$/;
|
||||
const RE_CACHE_FIRST_ASSETS = /[\da-f]{20}.*\.(js|css|woff2?|svg|png|jpg|jpeg|tgs|json|wasm)$/;
|
||||
const ACTIVATE_TIMEOUT = 3000;
|
||||
|
||||
const TEMP_DEBUG = true;
|
||||
|
||||
self.addEventListener('install', (e) => {
|
||||
if (DEBUG) {
|
||||
if (TEMP_DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('ServiceWorker installed');
|
||||
}
|
||||
@ -28,7 +29,7 @@ self.addEventListener('install', (e) => {
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (e) => {
|
||||
if (DEBUG) {
|
||||
if (TEMP_DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('ServiceWorker activated');
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { DEBUG, DEBUG_MORE, IS_TEST } from '../config';
|
||||
import { DEBUG_MORE, IS_TEST } from '../config';
|
||||
import { getActions } from '../global';
|
||||
import { formatShareText } from './deeplink';
|
||||
import { IS_ANDROID, IS_IOS, IS_SERVICE_WORKER_SUPPORTED } from './windowEnvironment';
|
||||
@ -12,6 +12,8 @@ type WorkerAction = {
|
||||
|
||||
const IGNORE_WORKER_PATH = '/k/';
|
||||
|
||||
const TEMP_DEBUG = true;
|
||||
|
||||
function handleWorkerMessage(e: MessageEvent) {
|
||||
const action: WorkerAction = e.data;
|
||||
if (DEBUG_MORE) {
|
||||
@ -52,7 +54,7 @@ if (IS_SERVICE_WORKER_SUPPORTED) {
|
||||
const registrations = await navigator.serviceWorker.getRegistrations();
|
||||
const ourRegistrations = registrations.filter((r) => !r.scope.includes(IGNORE_WORKER_PATH));
|
||||
if (ourRegistrations.length) {
|
||||
if (DEBUG) {
|
||||
if (TEMP_DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[SW] Hard reload detected, re-enabling Service Worker');
|
||||
}
|
||||
@ -62,23 +64,30 @@ if (IS_SERVICE_WORKER_SUPPORTED) {
|
||||
|
||||
await navigator.serviceWorker.register(new URL('../serviceWorker.ts', import.meta.url));
|
||||
|
||||
if (DEBUG) {
|
||||
if (TEMP_DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[SW] ServiceWorker registered');
|
||||
}
|
||||
|
||||
await navigator.serviceWorker.ready;
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Service Worker', navigator.serviceWorker?.controller?.scriptURL);
|
||||
|
||||
if (navigator.serviceWorker.controller) {
|
||||
if (DEBUG) {
|
||||
if (TEMP_DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[SW] ServiceWorker ready');
|
||||
}
|
||||
subscribeToWorker();
|
||||
} else {
|
||||
if (DEBUG) {
|
||||
if (TEMP_DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('[SW] ServiceWorker not available');
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('Assigned registration', await navigator.serviceWorker.getRegistration());
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('Ready promise', navigator.serviceWorker?.ready);
|
||||
}
|
||||
|
||||
if (!IS_IOS && !IS_ANDROID && !IS_TEST) {
|
||||
@ -86,7 +95,7 @@ if (IS_SERVICE_WORKER_SUPPORTED) {
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (DEBUG) {
|
||||
if (TEMP_DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('[SW] ServiceWorker registration failed: ', err);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user