@serwist/window 9.0.0-preview.3 → 9.0.0-preview.5
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/Serwist.d.ts +5 -7
- package/dist/Serwist.d.ts.map +1 -1
- package/dist/index.js +12 -12
- package/dist/messageSW.d.ts +1 -2
- package/dist/messageSW.d.ts.map +1 -1
- package/dist/utils/urlsMatch.d.ts +1 -1
- package/package.json +3 -3
- package/src/Serwist.ts +28 -42
- package/src/messageSW.ts +2 -5
- package/src/utils/urlsMatch.ts +1 -1
package/dist/Serwist.d.ts
CHANGED
|
@@ -31,13 +31,11 @@ export declare class Serwist extends SerwistEventTarget {
|
|
|
31
31
|
* options. The script URL and options are the same as those used when
|
|
32
32
|
* calling [navigator.serviceWorker.register(scriptURL, options)](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register).
|
|
33
33
|
*
|
|
34
|
-
* @param scriptURL The service worker script
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @param registerOptions The service worker options associated
|
|
38
|
-
* with this instance.
|
|
34
|
+
* @param scriptURL The service worker script associated with this instance. Using a
|
|
35
|
+
* [`TrustedScriptURL`](https://developer.mozilla.org/en-US/docs/Web/API/TrustedScriptURL) is supported.
|
|
36
|
+
* @param registerOptions The service worker options associated with this instance.
|
|
39
37
|
*/
|
|
40
|
-
constructor(scriptURL: string | TrustedScriptURL, registerOptions?:
|
|
38
|
+
constructor(scriptURL: string | TrustedScriptURL, registerOptions?: RegistrationOptions);
|
|
41
39
|
/**
|
|
42
40
|
* Registers a service worker for this instances script URL and service
|
|
43
41
|
* worker options. By default this method delays registration until after
|
|
@@ -108,7 +106,7 @@ export declare class Serwist extends SerwistEventTarget {
|
|
|
108
106
|
* @param data An object to send to the service worker
|
|
109
107
|
* @returns
|
|
110
108
|
*/
|
|
111
|
-
messageSW(data:
|
|
109
|
+
messageSW(data: any): Promise<any>;
|
|
112
110
|
/**
|
|
113
111
|
* Sends a `{type: 'SKIP_WAITING'}` message to the service worker that's
|
|
114
112
|
* currently in the `waiting` state associated with the current registration.
|
package/dist/Serwist.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Serwist.d.ts","sourceRoot":"","sources":["../src/Serwist.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAK1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAgBnE;;;;;;;;;;GAUG;AACH,qBAAa,OAAQ,SAAQ,kBAAkB;IAC7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA4B;IACvD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA2B;IAC5D,OAAO,CAAC,iBAAiB,CAAK;IAG9B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA2C;IACvE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA2C;IAC3E,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA2C;IAEhF,OAAO,CAAC,iBAAiB,CAA0B;IACnD,OAAO,CAAC,SAAS,CAAC,CAAU;IAC5B,OAAO,CAAC,wBAAwB,CAAC,CAAgB;IACjD,OAAO,CAAC,aAAa,CAAC,CAA4B;IAClD,OAAO,CAAC,GAAG,CAAC,CAAgB;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IACzD,OAAO,CAAC,WAAW,CAAC,CAAgB;IACpC,OAAO,CAAC,eAAe,CAAC,CAAS;IAEjC
|
|
1
|
+
{"version":3,"file":"Serwist.d.ts","sourceRoot":"","sources":["../src/Serwist.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAK1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAgBnE;;;;;;;;;;GAUG;AACH,qBAAa,OAAQ,SAAQ,kBAAkB;IAC7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA4B;IACvD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA2B;IAC5D,OAAO,CAAC,iBAAiB,CAAK;IAG9B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA2C;IACvE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA2C;IAC3E,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA2C;IAEhF,OAAO,CAAC,iBAAiB,CAA0B;IACnD,OAAO,CAAC,SAAS,CAAC,CAAU;IAC5B,OAAO,CAAC,wBAAwB,CAAC,CAAgB;IACjD,OAAO,CAAC,aAAa,CAAC,CAA4B;IAClD,OAAO,CAAC,GAAG,CAAC,CAAgB;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IACzD,OAAO,CAAC,WAAW,CAAC,CAAgB;IACpC,OAAO,CAAC,eAAe,CAAC,CAAS;IAEjC;;;;;;;;OAQG;gBACS,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,eAAe,GAAE,mBAAwB;IAY3F;;;;;;OAMG;IACG,QAAQ,CAAC,EACb,SAAiB,GAClB,GAAE;QACD;;;WAGG;QACH,SAAS,CAAC,EAAE,OAAO,CAAC;KAChB,GAAG,OAAO,CAAC,yBAAyB,GAAG,SAAS,CAAC;IA8FvD;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAY7B;;;;;;;;OAQG;IACH,IAAI,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,CAEnC;IAED;;;;;;;;;;;OAWG;IACH,IAAI,WAAW,IAAI,OAAO,CAAC,aAAa,CAAC,CAExC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,IAAI,OAAO,CAAC,aAAa,CAAC;IAM/B;;;;;;;;;;;;OAYG;IAEG,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAKxC;;;;;;OAMG;IACH,kBAAkB,IAAI,IAAI;IAM1B;;;;;;OAMG;IACH,OAAO,CAAC,6BAA6B;IAQrC;;;;;OAKG;YACW,eAAe;IAsB7B;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAsE7B;IAEF;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAqF7B;IAEF;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAuBlC;IAEF;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAuBzB;CACH;AAKD;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;GAaG"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Deferred, logger
|
|
1
|
+
import { Deferred, logger } from '@serwist/core/internal';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const messageSW = (sw, data)=>{
|
|
4
4
|
return new Promise((resolve)=>{
|
|
5
5
|
const messageChannel = new MessageChannel();
|
|
6
6
|
messageChannel.port1.onmessage = (event)=>{
|
|
@@ -10,7 +10,7 @@ function messageSW(sw, data) {
|
|
|
10
10
|
messageChannel.port2
|
|
11
11
|
]);
|
|
12
12
|
});
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
14
|
|
|
15
15
|
class SerwistEvent {
|
|
16
16
|
type;
|
|
@@ -82,7 +82,7 @@ class Serwist extends SerwistEventTarget {
|
|
|
82
82
|
async register({ immediate = false } = {}) {
|
|
83
83
|
if (process.env.NODE_ENV !== "production") {
|
|
84
84
|
if (this._registrationTime) {
|
|
85
|
-
logger.error("Cannot re-register a Serwist instance after it has
|
|
85
|
+
logger.error("Cannot re-register a Serwist instance after it has been registered. Create a new instance instead.");
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -103,15 +103,15 @@ class Serwist extends SerwistEventTarget {
|
|
|
103
103
|
const waitingSW = this._registration.waiting;
|
|
104
104
|
if (waitingSW && urlsMatch(waitingSW.scriptURL, this._scriptURL.toString())) {
|
|
105
105
|
this._sw = waitingSW;
|
|
106
|
-
|
|
106
|
+
void Promise.resolve().then(()=>{
|
|
107
107
|
this.dispatchEvent(new SerwistEvent("waiting", {
|
|
108
108
|
sw: waitingSW,
|
|
109
109
|
wasWaitingBeforeRegister: true
|
|
110
110
|
}));
|
|
111
111
|
if (process.env.NODE_ENV !== "production") {
|
|
112
|
-
logger.warn("A service worker was already waiting to activate
|
|
112
|
+
logger.warn("A service worker was already waiting to activate before this script was registered...");
|
|
113
113
|
}
|
|
114
|
-
})
|
|
114
|
+
});
|
|
115
115
|
}
|
|
116
116
|
if (this._sw) {
|
|
117
117
|
this._swDeferred.resolve(this._sw);
|
|
@@ -121,9 +121,9 @@ class Serwist extends SerwistEventTarget {
|
|
|
121
121
|
logger.log("Successfully registered service worker.", this._scriptURL.toString());
|
|
122
122
|
if (navigator.serviceWorker.controller) {
|
|
123
123
|
if (this._compatibleControllingSW) {
|
|
124
|
-
logger.debug("A service worker with the same script URL
|
|
124
|
+
logger.debug("A service worker with the same script URL is already controlling this page.");
|
|
125
125
|
} else {
|
|
126
|
-
logger.debug("A service worker with a different script URL is
|
|
126
|
+
logger.debug("A service worker with a different script URL is currently controlling the page. The browser is now fetching the new script now...");
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
const currentPageIsOutOfScope = ()=>{
|
|
@@ -132,7 +132,7 @@ class Serwist extends SerwistEventTarget {
|
|
|
132
132
|
return !location.pathname.startsWith(scopeURLBasePath);
|
|
133
133
|
};
|
|
134
134
|
if (currentPageIsOutOfScope()) {
|
|
135
|
-
logger.warn("The current page is not in scope for the registered
|
|
135
|
+
logger.warn("The current page is not in scope for the registered service worker. Was this a mistake?");
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
this._registration.addEventListener("updatefound", this._onUpdateFound);
|
|
@@ -142,7 +142,7 @@ class Serwist extends SerwistEventTarget {
|
|
|
142
142
|
async update() {
|
|
143
143
|
if (!this._registration) {
|
|
144
144
|
if (process.env.NODE_ENV !== "production") {
|
|
145
|
-
logger.error("Cannot update a Serwist instance without
|
|
145
|
+
logger.error("Cannot update a Serwist instance without being registered. Register the Serwist instance first.");
|
|
146
146
|
}
|
|
147
147
|
return;
|
|
148
148
|
}
|
|
@@ -188,7 +188,7 @@ class Serwist extends SerwistEventTarget {
|
|
|
188
188
|
_onUpdateFound = (originalEvent)=>{
|
|
189
189
|
const registration = this._registration;
|
|
190
190
|
const installingSW = registration.installing;
|
|
191
|
-
const updateLikelyTriggeredExternally = this._updateFoundCount > 0 || !urlsMatch(installingSW.scriptURL, this._scriptURL.toString()) || performance.now() > this._registrationTime + REGISTRATION_TIMEOUT_DURATION
|
|
191
|
+
const updateLikelyTriggeredExternally = this._updateFoundCount > 0 || !urlsMatch(installingSW.scriptURL, this._scriptURL.toString()) || performance.now() > this._registrationTime + REGISTRATION_TIMEOUT_DURATION;
|
|
192
192
|
if (updateLikelyTriggeredExternally) {
|
|
193
193
|
this._externalSW = installingSW;
|
|
194
194
|
registration.removeEventListener("updatefound", this._onUpdateFound);
|
package/dist/messageSW.d.ts
CHANGED
|
@@ -11,6 +11,5 @@
|
|
|
11
11
|
* @param data An object to send to the service worker.
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
|
-
declare
|
|
15
|
-
export { messageSW };
|
|
14
|
+
export declare const messageSW: (sw: ServiceWorker, data: any) => Promise<any>;
|
|
16
15
|
//# sourceMappingURL=messageSW.d.ts.map
|
package/dist/messageSW.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageSW.d.ts","sourceRoot":"","sources":["../src/messageSW.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"messageSW.d.ts","sourceRoot":"","sources":["../src/messageSW.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS,OAAQ,aAAa,QAAQ,GAAG,KAAG,QAAQ,GAAG,CAQnE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/window",
|
|
3
|
-
"version": "9.0.0-preview.
|
|
3
|
+
"version": "9.0.0-preview.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Simplifies communications with Serwist packages running in the service worker",
|
|
6
6
|
"files": [
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@types/trusted-types": "2.0.7",
|
|
35
|
-
"@serwist/core": "9.0.0-preview.
|
|
35
|
+
"@serwist/core": "9.0.0-preview.5"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"rollup": "4.9.6",
|
|
39
39
|
"typescript": "5.4.0-dev.20240206",
|
|
40
|
-
"@serwist/constants": "9.0.0-preview.
|
|
40
|
+
"@serwist/constants": "9.0.0-preview.5"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"typescript": ">=5.0.0"
|
package/src/Serwist.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { Deferred,
|
|
9
|
+
import { Deferred, logger } from "@serwist/core/internal";
|
|
10
10
|
import type { TrustedScriptURL } from "trusted-types/lib";
|
|
11
11
|
|
|
12
12
|
import { messageSW } from "./messageSW.js";
|
|
@@ -26,7 +26,7 @@ const REGISTRATION_TIMEOUT_DURATION = 60000;
|
|
|
26
26
|
|
|
27
27
|
// The de facto standard message that a service worker should be listening for
|
|
28
28
|
// to trigger a call to skipWaiting().
|
|
29
|
-
const SKIP_WAITING_MESSAGE = { type: "SKIP_WAITING" };
|
|
29
|
+
const SKIP_WAITING_MESSAGE = { type: "SKIP_WAITING" } as const;
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* A class to aid in handling service worker registration, updates, and
|
|
@@ -63,14 +63,11 @@ export class Serwist extends SerwistEventTarget {
|
|
|
63
63
|
* options. The script URL and options are the same as those used when
|
|
64
64
|
* calling [navigator.serviceWorker.register(scriptURL, options)](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register).
|
|
65
65
|
*
|
|
66
|
-
* @param scriptURL The service worker script
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* @param registerOptions The service worker options associated
|
|
70
|
-
* with this instance.
|
|
66
|
+
* @param scriptURL The service worker script associated with this instance. Using a
|
|
67
|
+
* [`TrustedScriptURL`](https://developer.mozilla.org/en-US/docs/Web/API/TrustedScriptURL) is supported.
|
|
68
|
+
* @param registerOptions The service worker options associated with this instance.
|
|
71
69
|
*/
|
|
72
|
-
|
|
73
|
-
constructor(scriptURL: string | TrustedScriptURL, registerOptions: {} = {}) {
|
|
70
|
+
constructor(scriptURL: string | TrustedScriptURL, registerOptions: RegistrationOptions = {}) {
|
|
74
71
|
super();
|
|
75
72
|
|
|
76
73
|
this._scriptURL = scriptURL;
|
|
@@ -100,7 +97,7 @@ export class Serwist extends SerwistEventTarget {
|
|
|
100
97
|
} = {}): Promise<ServiceWorkerRegistration | undefined> {
|
|
101
98
|
if (process.env.NODE_ENV !== "production") {
|
|
102
99
|
if (this._registrationTime) {
|
|
103
|
-
logger.error("Cannot re-register a Serwist instance after it has
|
|
100
|
+
logger.error("Cannot re-register a Serwist instance after it has been registered. Create a new instance instead.");
|
|
104
101
|
return;
|
|
105
102
|
}
|
|
106
103
|
}
|
|
@@ -114,7 +111,7 @@ export class Serwist extends SerwistEventTarget {
|
|
|
114
111
|
this._isUpdate = Boolean(navigator.serviceWorker.controller);
|
|
115
112
|
|
|
116
113
|
// Before registering, attempt to determine if a SW is already controlling
|
|
117
|
-
// the page
|
|
114
|
+
// the page and if that SW script (and version, if specified) matches this
|
|
118
115
|
// instance's script.
|
|
119
116
|
this._compatibleControllingSW = this._getControllingSWIfCompatible();
|
|
120
117
|
|
|
@@ -137,25 +134,23 @@ export class Serwist extends SerwistEventTarget {
|
|
|
137
134
|
// https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#waiting
|
|
138
135
|
const waitingSW = this._registration.waiting;
|
|
139
136
|
if (waitingSW && urlsMatch(waitingSW.scriptURL, this._scriptURL.toString())) {
|
|
140
|
-
// Store the waiting SW as the "own"
|
|
137
|
+
// Store the waiting SW as the "own" SW, even if it means overwriting
|
|
141
138
|
// a compatible controller.
|
|
142
139
|
this._sw = waitingSW;
|
|
143
140
|
|
|
144
141
|
// Run this in the next microtask, so any code that adds an event
|
|
145
142
|
// listener after awaiting `register()` will get this event.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}),
|
|
158
|
-
);
|
|
143
|
+
void Promise.resolve().then(() => {
|
|
144
|
+
this.dispatchEvent(
|
|
145
|
+
new SerwistEvent("waiting", {
|
|
146
|
+
sw: waitingSW,
|
|
147
|
+
wasWaitingBeforeRegister: true,
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
150
|
+
if (process.env.NODE_ENV !== "production") {
|
|
151
|
+
logger.warn("A service worker was already waiting to activate before this script was registered...");
|
|
152
|
+
}
|
|
153
|
+
});
|
|
159
154
|
}
|
|
160
155
|
|
|
161
156
|
// If an "own" SW is already set, resolve the deferred.
|
|
@@ -169,12 +164,10 @@ export class Serwist extends SerwistEventTarget {
|
|
|
169
164
|
|
|
170
165
|
if (navigator.serviceWorker.controller) {
|
|
171
166
|
if (this._compatibleControllingSW) {
|
|
172
|
-
logger.debug("A service worker with the same script URL
|
|
167
|
+
logger.debug("A service worker with the same script URL is already controlling this page.");
|
|
173
168
|
} else {
|
|
174
169
|
logger.debug(
|
|
175
|
-
"A service worker with a different script URL is "
|
|
176
|
-
"currently controlling the page. The browser is now fetching " +
|
|
177
|
-
"the new script now...",
|
|
170
|
+
"A service worker with a different script URL is currently controlling the page. The browser is now fetching the new script now...",
|
|
178
171
|
);
|
|
179
172
|
}
|
|
180
173
|
}
|
|
@@ -185,7 +178,7 @@ export class Serwist extends SerwistEventTarget {
|
|
|
185
178
|
return !location.pathname.startsWith(scopeURLBasePath);
|
|
186
179
|
};
|
|
187
180
|
if (currentPageIsOutOfScope()) {
|
|
188
|
-
logger.warn("The current page is not in scope for the registered
|
|
181
|
+
logger.warn("The current page is not in scope for the registered service worker. Was this a mistake?");
|
|
189
182
|
}
|
|
190
183
|
}
|
|
191
184
|
|
|
@@ -201,7 +194,7 @@ export class Serwist extends SerwistEventTarget {
|
|
|
201
194
|
async update(): Promise<void> {
|
|
202
195
|
if (!this._registration) {
|
|
203
196
|
if (process.env.NODE_ENV !== "production") {
|
|
204
|
-
logger.error("Cannot update a Serwist instance without
|
|
197
|
+
logger.error("Cannot update a Serwist instance without being registered. Register the Serwist instance first.");
|
|
205
198
|
}
|
|
206
199
|
return;
|
|
207
200
|
}
|
|
@@ -274,8 +267,7 @@ export class Serwist extends SerwistEventTarget {
|
|
|
274
267
|
* @returns
|
|
275
268
|
*/
|
|
276
269
|
// We might be able to change the 'data' type to Record<string, unknown> in the future.
|
|
277
|
-
|
|
278
|
-
async messageSW(data: object): Promise<any> {
|
|
270
|
+
async messageSW(data: any): Promise<any> {
|
|
279
271
|
const sw = await this.getSW();
|
|
280
272
|
return messageSW(sw, data);
|
|
281
273
|
}
|
|
@@ -370,11 +362,9 @@ export class Serwist extends SerwistEventTarget {
|
|
|
370
362
|
// If all of the above are false, then we use a time-based heuristic:
|
|
371
363
|
// Any `updatefound` event that occurs long after our registration is
|
|
372
364
|
// assumed to be external.
|
|
373
|
-
performance.now() > this._registrationTime + REGISTRATION_TIMEOUT_DURATION
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
true
|
|
377
|
-
: false;
|
|
365
|
+
performance.now() > this._registrationTime + REGISTRATION_TIMEOUT_DURATION;
|
|
366
|
+
// If any of the above are not true, we assume the update was
|
|
367
|
+
// triggered by this instance.
|
|
378
368
|
|
|
379
369
|
if (updateLikelyTriggeredExternally) {
|
|
380
370
|
this._externalSW = installingSW;
|
|
@@ -539,8 +529,6 @@ export class Serwist extends SerwistEventTarget {
|
|
|
539
529
|
* @param originalEvent
|
|
540
530
|
*/
|
|
541
531
|
private readonly _onMessage = async (originalEvent: MessageEvent) => {
|
|
542
|
-
// Can't change type 'any' of data.
|
|
543
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
544
532
|
const { data, ports, source } = originalEvent;
|
|
545
533
|
|
|
546
534
|
// Wait until there's an "own" service worker. This is used to buffer
|
|
@@ -556,8 +544,6 @@ export class Serwist extends SerwistEventTarget {
|
|
|
556
544
|
if (this._ownSWs.has(source as ServiceWorker)) {
|
|
557
545
|
this.dispatchEvent(
|
|
558
546
|
new SerwistEvent("message", {
|
|
559
|
-
// Can't change type 'any' of data.
|
|
560
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
561
547
|
data,
|
|
562
548
|
originalEvent,
|
|
563
549
|
ports,
|
package/src/messageSW.ts
CHANGED
|
@@ -19,8 +19,7 @@
|
|
|
19
19
|
* @param data An object to send to the service worker.
|
|
20
20
|
* @returns
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
|
-
function messageSW(sw: ServiceWorker, data: {}): Promise<any> {
|
|
22
|
+
export const messageSW = (sw: ServiceWorker, data: any): Promise<any> => {
|
|
24
23
|
return new Promise((resolve) => {
|
|
25
24
|
const messageChannel = new MessageChannel();
|
|
26
25
|
messageChannel.port1.onmessage = (event: MessageEvent) => {
|
|
@@ -28,6 +27,4 @@ function messageSW(sw: ServiceWorker, data: {}): Promise<any> {
|
|
|
28
27
|
};
|
|
29
28
|
sw.postMessage(data, [messageChannel.port2]);
|
|
30
29
|
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { messageSW };
|
|
30
|
+
};
|
package/src/utils/urlsMatch.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Returns true if two URLs have the same `.href` property. The
|
|
10
|
+
* Returns true if two URLs have the same `.href` property. The URLs can be
|
|
11
11
|
* relative, and if they are the current location href is used to resolve URLs.
|
|
12
12
|
*
|
|
13
13
|
* @private
|