textbrowser 0.54.8 → 0.54.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +8 -0
- package/dist/activateCallback-es.js +23 -0
- package/dist/sw-helper.js +36 -6
- package/package.json +1 -1
- package/resources/activateCallback.js +23 -0
package/CHANGES.md
CHANGED
|
@@ -55,10 +55,12 @@ async function activateCallback ({
|
|
|
55
55
|
// anyways); also important to avoid conflicts with
|
|
56
56
|
// already-running versions upon future sw updates
|
|
57
57
|
log('Activate: Callback called');
|
|
58
|
+
log('Activate: Fetching files manifest', files);
|
|
58
59
|
const r = await fetch(files);
|
|
59
60
|
const {groups} = /** @type {import('./utils/WorkInfo.js').FilesObject} */ (
|
|
60
61
|
await r.json()
|
|
61
62
|
);
|
|
63
|
+
log('Activate: Manifest loaded; groups:', groups.length);
|
|
62
64
|
|
|
63
65
|
/* eslint-disable jsdoc/reject-any-type -- Generic */
|
|
64
66
|
/**
|
|
@@ -67,6 +69,7 @@ async function activateCallback ({
|
|
|
67
69
|
*/
|
|
68
70
|
const addJSONFetch = (arr, path) => {
|
|
69
71
|
/* eslint-enable jsdoc/reject-any-type -- Generic */
|
|
72
|
+
log('Activate: Queueing JSON fetch', basePath + path);
|
|
70
73
|
arr.push(
|
|
71
74
|
(async () => (await fetch(basePath + path)).json())()
|
|
72
75
|
);
|
|
@@ -89,6 +92,13 @@ async function activateCallback ({
|
|
|
89
92
|
const metadataFiles = [];
|
|
90
93
|
groups.forEach(
|
|
91
94
|
({files: fileObjs, metadataBaseDirectory, schemaBaseDirectory}) => {
|
|
95
|
+
log(
|
|
96
|
+
'Activate: Processing group',
|
|
97
|
+
metadataBaseDirectory,
|
|
98
|
+
schemaBaseDirectory,
|
|
99
|
+
'files:',
|
|
100
|
+
fileObjs.length
|
|
101
|
+
);
|
|
92
102
|
fileObjs.forEach(({file: {$ref: filePath}, metadataFile, schemaFile, name}) => {
|
|
93
103
|
// We don't i18nize the name here
|
|
94
104
|
dataFileNames.push(name);
|
|
@@ -98,6 +108,7 @@ async function activateCallback ({
|
|
|
98
108
|
});
|
|
99
109
|
}
|
|
100
110
|
);
|
|
111
|
+
log('Activate: Awaiting queued fetches; works:', dataFiles.length);
|
|
101
112
|
const promises = await Promise.all([
|
|
102
113
|
...dataFiles, ...schemaFiles, ...metadataFiles
|
|
103
114
|
]);
|
|
@@ -109,11 +120,14 @@ async function activateCallback ({
|
|
|
109
120
|
|
|
110
121
|
log('Activate: Files fetched');
|
|
111
122
|
const dbName = namespace + '-textbrowser-cache-data';
|
|
123
|
+
log('Activate: Deleting existing database', dbName);
|
|
112
124
|
indexedDB.deleteDatabase(dbName);
|
|
113
125
|
return new Promise((resolve, reject) => {
|
|
126
|
+
log('Activate: Opening database', dbName);
|
|
114
127
|
const req = indexedDB.open(dbName);
|
|
115
128
|
// @ts-expect-error Ok
|
|
116
129
|
req.addEventListener('upgradeneeded', ({target: {result: db}}) => {
|
|
130
|
+
log('Activate: Database upgrade needed', dbName);
|
|
117
131
|
db.onversionchange = () => {
|
|
118
132
|
db.close();
|
|
119
133
|
const err = /** @type {Error & {type: string}} */ (new Error('versionchange'));
|
|
@@ -122,6 +136,7 @@ async function activateCallback ({
|
|
|
122
136
|
};
|
|
123
137
|
dataFileResponses.forEach(({data: tableRows}, i) => {
|
|
124
138
|
const dataFileName = dataFileNames[i];
|
|
139
|
+
log('Activate: Creating object store', dataFileName, 'rows:', tableRows.length);
|
|
125
140
|
const store = db.createObjectStore('files-to-cache-' + dataFileName);
|
|
126
141
|
|
|
127
142
|
const schemaFileResponse = schemaFileResponses[i];
|
|
@@ -180,6 +195,12 @@ async function activateCallback ({
|
|
|
180
195
|
});
|
|
181
196
|
|
|
182
197
|
const uniqueColumnIndexes = [...new Set(columnIndexes)];
|
|
198
|
+
log(
|
|
199
|
+
'Activate: Preparing rows for store',
|
|
200
|
+
dataFileName,
|
|
201
|
+
'unique indexes:',
|
|
202
|
+
uniqueColumnIndexes.length
|
|
203
|
+
);
|
|
183
204
|
|
|
184
205
|
tableRows.forEach((tableRow, j) => {
|
|
185
206
|
// Todo: Optionally send notice when complete
|
|
@@ -203,6 +224,7 @@ async function activateCallback ({
|
|
|
203
224
|
// log('objRow', objRow);
|
|
204
225
|
store.put(objRow, j);
|
|
205
226
|
});
|
|
227
|
+
log('Activate: Finished object store population', dataFileName);
|
|
206
228
|
});
|
|
207
229
|
});
|
|
208
230
|
|
|
@@ -218,6 +240,7 @@ async function activateCallback ({
|
|
|
218
240
|
* @param {Event & {error?: Error}} ev
|
|
219
241
|
*/
|
|
220
242
|
const onerr = (ev) => {
|
|
243
|
+
log('Activate: Database request error event fired');
|
|
221
244
|
const error = /** @type {Error & {type: string}} */ (
|
|
222
245
|
ev.error ?? new Error('dbError')
|
|
223
246
|
);
|
package/dist/sw-helper.js
CHANGED
|
@@ -184,7 +184,7 @@ function swHelper (self) {
|
|
|
184
184
|
* @returns {Promise<void>}
|
|
185
185
|
*/
|
|
186
186
|
async function install (time) {
|
|
187
|
-
post({type: 'beginInstall'});
|
|
187
|
+
await post({type: 'beginInstall'});
|
|
188
188
|
log(`Install: Trying, attempt ${time}`);
|
|
189
189
|
const now = Date.now();
|
|
190
190
|
const json = await getJSON(/** @type {string} */ (pathToUserJSON));
|
|
@@ -237,11 +237,26 @@ function swHelper (self) {
|
|
|
237
237
|
...userDataFiles,
|
|
238
238
|
...stylesheets
|
|
239
239
|
];
|
|
240
|
+
log(`Install: Pre-fetching ${urlsToPrefetch.length} assets`);
|
|
241
|
+
const pendingAssets = new Set();
|
|
242
|
+
const pendingLogTimer = setInterval(() => {
|
|
243
|
+
if (pendingAssets.size) {
|
|
244
|
+
log(
|
|
245
|
+
`Install: Still pending ${pendingAssets.size} assets: ` +
|
|
246
|
+
JSON.stringify([...pendingAssets])
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
}, 10000);
|
|
240
250
|
// .map((url) => url === 'index.html' ? new Request(url, {cache: 'reload'}) : url)
|
|
241
251
|
try {
|
|
242
|
-
const cachePromises = urlsToPrefetch.map(async (urlToPrefetch) => {
|
|
252
|
+
const cachePromises = urlsToPrefetch.map(async (urlToPrefetch, idx) => {
|
|
243
253
|
// This constructs a new URL object using the service worker's script
|
|
244
254
|
// location as the base for relative URLs.
|
|
255
|
+
pendingAssets.add(urlToPrefetch);
|
|
256
|
+
log(
|
|
257
|
+
`Install: Fetching asset ${idx + 1}/` +
|
|
258
|
+
`${urlsToPrefetch.length}: ${urlToPrefetch}`
|
|
259
|
+
);
|
|
245
260
|
const url = new URL(urlToPrefetch, location.href);
|
|
246
261
|
url.search += (url.search ? '&' : '?') + 'cache-bust=' + now;
|
|
247
262
|
const request = new Request(url, {mode: 'no-cors'});
|
|
@@ -251,8 +266,12 @@ function swHelper (self) {
|
|
|
251
266
|
throw new Error('request for ' + urlToPrefetch +
|
|
252
267
|
' failed with status ' + response.statusText);
|
|
253
268
|
}
|
|
254
|
-
|
|
269
|
+
await cache.put(urlToPrefetch, response);
|
|
270
|
+
log(`Install: Cached asset ${idx + 1}/${urlsToPrefetch.length}: ${urlToPrefetch}`);
|
|
271
|
+
pendingAssets.delete(urlToPrefetch);
|
|
272
|
+
return;
|
|
255
273
|
} catch (error) {
|
|
274
|
+
pendingAssets.delete(urlToPrefetch);
|
|
256
275
|
logError(
|
|
257
276
|
/** @type {Error} */
|
|
258
277
|
(error),
|
|
@@ -271,6 +290,8 @@ function swHelper (self) {
|
|
|
271
290
|
);
|
|
272
291
|
// Failing gives chance for a new client to re-trigger install?
|
|
273
292
|
throw error;
|
|
293
|
+
} finally {
|
|
294
|
+
clearInterval(pendingLogTimer);
|
|
274
295
|
}
|
|
275
296
|
|
|
276
297
|
// An install update event will not be reported until controlled,
|
|
@@ -279,7 +300,7 @@ function swHelper (self) {
|
|
|
279
300
|
|
|
280
301
|
// Although we only need one client to which to send
|
|
281
302
|
// arguments, we want to signal phase complete to all
|
|
282
|
-
post({type: 'finishedInstall'});
|
|
303
|
+
await post({type: 'finishedInstall'});
|
|
283
304
|
}
|
|
284
305
|
|
|
285
306
|
/**
|
|
@@ -288,7 +309,12 @@ function swHelper (self) {
|
|
|
288
309
|
* @returns {Promise<void>}
|
|
289
310
|
*/
|
|
290
311
|
async function activate (time) {
|
|
291
|
-
|
|
312
|
+
console.log('Activate event worker callback entered', time);
|
|
313
|
+
await post({
|
|
314
|
+
type: 'log',
|
|
315
|
+
message: `Activate: Event callback entered (attempt ${time})`
|
|
316
|
+
});
|
|
317
|
+
await post({type: 'beginActivate'});
|
|
292
318
|
log(`Activate: Trying, attempt ${time}`);
|
|
293
319
|
const [json, cacheNames] = await Promise.all([
|
|
294
320
|
getJSON(/** @type {string} */ (pathToUserJSON)),
|
|
@@ -308,9 +334,12 @@ function swHelper (self) {
|
|
|
308
334
|
await activateCallback({namespace, files, basePath, log});
|
|
309
335
|
log('Activate: Database changes completed');
|
|
310
336
|
|
|
337
|
+
await self.clients.claim();
|
|
338
|
+
log('Activate: Clients claimed');
|
|
339
|
+
|
|
311
340
|
log(`Activate: Posting finished message to clients`);
|
|
312
341
|
// Signal phase complete to all clients
|
|
313
|
-
post({type: 'finishedActivate'});
|
|
342
|
+
await post({type: 'finishedActivate'});
|
|
314
343
|
}
|
|
315
344
|
|
|
316
345
|
// @ts-expect-error Ok
|
|
@@ -327,6 +356,7 @@ function swHelper (self) {
|
|
|
327
356
|
});
|
|
328
357
|
|
|
329
358
|
self.addEventListener('activate', (e) => {
|
|
359
|
+
console.log('sw activate event fired');
|
|
330
360
|
// Erring is of no present use here:
|
|
331
361
|
// https://github.com/w3c/ServiceWorker/issues/659#issuecomment-384919053
|
|
332
362
|
e.waitUntil(tryAndRetry(activate, 5 * minutes, 'Error activating'));
|
package/package.json
CHANGED
|
@@ -55,10 +55,12 @@ export default async function activateCallback ({
|
|
|
55
55
|
// anyways); also important to avoid conflicts with
|
|
56
56
|
// already-running versions upon future sw updates
|
|
57
57
|
log('Activate: Callback called');
|
|
58
|
+
log('Activate: Fetching files manifest', files);
|
|
58
59
|
const r = await fetch(files);
|
|
59
60
|
const {groups} = /** @type {import('./utils/WorkInfo.js').FilesObject} */ (
|
|
60
61
|
await r.json()
|
|
61
62
|
);
|
|
63
|
+
log('Activate: Manifest loaded; groups:', groups.length);
|
|
62
64
|
|
|
63
65
|
/* eslint-disable jsdoc/reject-any-type -- Generic */
|
|
64
66
|
/**
|
|
@@ -67,6 +69,7 @@ export default async function activateCallback ({
|
|
|
67
69
|
*/
|
|
68
70
|
const addJSONFetch = (arr, path) => {
|
|
69
71
|
/* eslint-enable jsdoc/reject-any-type -- Generic */
|
|
72
|
+
log('Activate: Queueing JSON fetch', basePath + path);
|
|
70
73
|
arr.push(
|
|
71
74
|
(async () => (await fetch(basePath + path)).json())()
|
|
72
75
|
);
|
|
@@ -89,6 +92,13 @@ export default async function activateCallback ({
|
|
|
89
92
|
const metadataFiles = [];
|
|
90
93
|
groups.forEach(
|
|
91
94
|
({files: fileObjs, metadataBaseDirectory, schemaBaseDirectory}) => {
|
|
95
|
+
log(
|
|
96
|
+
'Activate: Processing group',
|
|
97
|
+
metadataBaseDirectory,
|
|
98
|
+
schemaBaseDirectory,
|
|
99
|
+
'files:',
|
|
100
|
+
fileObjs.length
|
|
101
|
+
);
|
|
92
102
|
fileObjs.forEach(({file: {$ref: filePath}, metadataFile, schemaFile, name}) => {
|
|
93
103
|
// We don't i18nize the name here
|
|
94
104
|
dataFileNames.push(name);
|
|
@@ -98,6 +108,7 @@ export default async function activateCallback ({
|
|
|
98
108
|
});
|
|
99
109
|
}
|
|
100
110
|
);
|
|
111
|
+
log('Activate: Awaiting queued fetches; works:', dataFiles.length);
|
|
101
112
|
const promises = await Promise.all([
|
|
102
113
|
...dataFiles, ...schemaFiles, ...metadataFiles
|
|
103
114
|
]);
|
|
@@ -109,11 +120,14 @@ export default async function activateCallback ({
|
|
|
109
120
|
|
|
110
121
|
log('Activate: Files fetched');
|
|
111
122
|
const dbName = namespace + '-textbrowser-cache-data';
|
|
123
|
+
log('Activate: Deleting existing database', dbName);
|
|
112
124
|
indexedDB.deleteDatabase(dbName);
|
|
113
125
|
return new Promise((resolve, reject) => {
|
|
126
|
+
log('Activate: Opening database', dbName);
|
|
114
127
|
const req = indexedDB.open(dbName);
|
|
115
128
|
// @ts-expect-error Ok
|
|
116
129
|
req.addEventListener('upgradeneeded', ({target: {result: db}}) => {
|
|
130
|
+
log('Activate: Database upgrade needed', dbName);
|
|
117
131
|
db.onversionchange = () => {
|
|
118
132
|
db.close();
|
|
119
133
|
const err = /** @type {Error & {type: string}} */ (new Error('versionchange'));
|
|
@@ -122,6 +136,7 @@ export default async function activateCallback ({
|
|
|
122
136
|
};
|
|
123
137
|
dataFileResponses.forEach(({data: tableRows}, i) => {
|
|
124
138
|
const dataFileName = dataFileNames[i];
|
|
139
|
+
log('Activate: Creating object store', dataFileName, 'rows:', tableRows.length);
|
|
125
140
|
const store = db.createObjectStore('files-to-cache-' + dataFileName);
|
|
126
141
|
|
|
127
142
|
const schemaFileResponse = schemaFileResponses[i];
|
|
@@ -180,6 +195,12 @@ export default async function activateCallback ({
|
|
|
180
195
|
});
|
|
181
196
|
|
|
182
197
|
const uniqueColumnIndexes = [...new Set(columnIndexes)];
|
|
198
|
+
log(
|
|
199
|
+
'Activate: Preparing rows for store',
|
|
200
|
+
dataFileName,
|
|
201
|
+
'unique indexes:',
|
|
202
|
+
uniqueColumnIndexes.length
|
|
203
|
+
);
|
|
183
204
|
|
|
184
205
|
tableRows.forEach((tableRow, j) => {
|
|
185
206
|
// Todo: Optionally send notice when complete
|
|
@@ -203,6 +224,7 @@ export default async function activateCallback ({
|
|
|
203
224
|
// log('objRow', objRow);
|
|
204
225
|
store.put(objRow, j);
|
|
205
226
|
});
|
|
227
|
+
log('Activate: Finished object store population', dataFileName);
|
|
206
228
|
});
|
|
207
229
|
});
|
|
208
230
|
|
|
@@ -218,6 +240,7 @@ export default async function activateCallback ({
|
|
|
218
240
|
* @param {Event & {error?: Error}} ev
|
|
219
241
|
*/
|
|
220
242
|
const onerr = (ev) => {
|
|
243
|
+
log('Activate: Database request error event fired');
|
|
221
244
|
const error = /** @type {Error & {type: string}} */ (
|
|
222
245
|
ev.error ?? new Error('dbError')
|
|
223
246
|
);
|