zip-peek 0.6.5-beta.2 → 0.6.6
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/dist/index.js +24 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -95,8 +95,15 @@ async function ensureZipServiceWorkerRegistered({ workerUrl, scopeUrl, reloadOnF
|
|
|
95
95
|
zipServiceWorkerScriptMatches(existing.waiting?.scriptURL, workerUrl) ||
|
|
96
96
|
zipServiceWorkerScriptMatches(existing.installing?.scriptURL, workerUrl));
|
|
97
97
|
if (!alreadyRegistered) {
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
try {
|
|
99
|
+
await navigator.serviceWorker.register(workerUrl, { scope: scopeUrl });
|
|
100
|
+
console.log("Zip service worker registered successfully");
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
const context = describeRegistrationFailureContext();
|
|
104
|
+
console.error("zip-peek: service worker registration failed", context, error);
|
|
105
|
+
throw attachZipPeekInfo(error, `Service worker registration failed (${context})`);
|
|
106
|
+
}
|
|
100
107
|
}
|
|
101
108
|
else {
|
|
102
109
|
console.log("Zip service worker already registered; skipping register().");
|
|
@@ -108,8 +115,8 @@ async function ensureZipServiceWorkerRegistered({ workerUrl, scopeUrl, reloadOnF
|
|
|
108
115
|
}
|
|
109
116
|
return false;
|
|
110
117
|
}
|
|
111
|
-
/**
|
|
112
|
-
function
|
|
118
|
+
/** Context attached when service worker registration fails. */
|
|
119
|
+
function describeRegistrationFailureContext() {
|
|
113
120
|
const cookieEnabled = typeof navigator !== "undefined" ? navigator.cookieEnabled : false;
|
|
114
121
|
let localStorageAccess = "ok";
|
|
115
122
|
try {
|
|
@@ -119,7 +126,14 @@ function describeClientStorageAccess() {
|
|
|
119
126
|
catch (error) {
|
|
120
127
|
localStorageAccess = error instanceof Error ? error.message : String(error);
|
|
121
128
|
}
|
|
122
|
-
return
|
|
129
|
+
return [
|
|
130
|
+
`visibility=${document.visibilityState}`,
|
|
131
|
+
`hidden=${document.hidden}`,
|
|
132
|
+
`online=${navigator.onLine}`,
|
|
133
|
+
`hasController=${Boolean(navigator.serviceWorker?.controller)}`,
|
|
134
|
+
`cookieEnabled=${cookieEnabled}`,
|
|
135
|
+
`localStorage=${localStorageAccess}`,
|
|
136
|
+
].join("; ");
|
|
123
137
|
}
|
|
124
138
|
function attachZipPeekInfo(error, info) {
|
|
125
139
|
const err = (0, types_1.toZipPeekError)(error);
|
|
@@ -359,7 +373,11 @@ async function initZipPeek({ workerUrl, scopeUrl, reloadOnFirstInstall = true, c
|
|
|
359
373
|
});
|
|
360
374
|
}
|
|
361
375
|
catch (error) {
|
|
362
|
-
|
|
376
|
+
const err = error;
|
|
377
|
+
if (!err.zipPeekInfo) {
|
|
378
|
+
throw attachZipPeekInfo(error, `Service worker registration failed (${describeRegistrationFailureContext()})`);
|
|
379
|
+
}
|
|
380
|
+
throw error;
|
|
363
381
|
}
|
|
364
382
|
if (reloaded) {
|
|
365
383
|
return { reloaded: true, initialized: false };
|