@statewalker/webrun-http-browser 0.6.4 → 0.6.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/README.md CHANGED
@@ -191,9 +191,11 @@ declare const self: ServiceWorkerGlobalScope & { RELAY_OPTIONS?: RelayServiceWor
191
191
  </script>
192
192
  ```
193
193
 
194
- Pass `swUrl` explicitly. Its default is `index-sw.js` next to the module, a
195
- file the build does not produce. `timeout` bounds the wait for the worker to
196
- activate. If the worker cannot start, every call the parent makes on the port
194
+ Without `swUrl` the handler registers the bundle's own `dist/relay-sw.js`,
195
+ and without `scopeUrl` the scope is that worker's directory, `dist/`: the
196
+ widest scope a script there may claim without a `Service-Worker-Allowed`
197
+ header. A relay page that serves services anywhere else passes both, as above.
198
+ `timeout` bounds the wait for the worker to activate. If the worker cannot start, every call the parent makes on the port
197
199
  is answered with that error, so the parent's `initHttpService` /
198
200
  `callHttpService` reject instead of hanging.
199
201
 
@@ -229,7 +231,7 @@ importScripts("/path/to/@statewalker/webrun-http-browser/dist/sw-worker.js");
229
231
  | Option | Default | Meaning |
230
232
  | --- | --- | --- |
231
233
  | `key` | required | First URL segment under the scope that the worker routes to this page. |
232
- | `serviceWorkerUrl` | none; pass it | Resolved against `location.href`. An unresolvable value throws `Invalid serviceWorkerUrl: "<value>" (relative to <href>)`. |
234
+ | `serviceWorkerUrl` | `sw-worker.js` at the scope | Resolved against `location.href`. An unresolvable value throws `Invalid serviceWorkerUrl: "<value>" (relative to <href>)`. |
233
235
  | `scope` | directory of `serviceWorkerUrl` | Registration scope. |
234
236
  | `timeout` | `30_000` | Upper bound, in ms, for activation, control and the adapter's handshake. Past it `start()` rejects with a `ServiceWorkerControlError`. |
235
237
  | `reloadIfUncontrolled` | `false` | Reload the page once instead of rejecting when it stays uncontrolled. |
@@ -392,8 +394,9 @@ The worker keeps the claimed keys and client ids in IndexedDB (`claimedKeys`,
392
394
  relay keeps its registry under `clientsIds` as `{ clientId, path }` entries and
393
395
  still reads the older bare-client-id shape.
394
396
 
395
- `SwPortHandler.stop()` unregisters every ServiceWorker registration of the
396
- origin, not only its own.
397
+ `SwPortHandler.stop()` unregisters only the registration its own `start()`
398
+ made; other workers on the origin stay registered. After a `start()` that
399
+ rejected, `stop()` unregisters nothing, since that attempt kept the worker.
397
400
 
398
401
  ### A page can load uncontrolled although its worker is active
399
402
 
@@ -439,11 +442,12 @@ message size limit. `sendHttpRequest` and `handleHttpRequests` are marked
439
442
  this package still use the deprecated pair internally. A caller that stops
440
443
  reading early does tell the peer to stop producing.
441
444
 
442
- ### Defaults that point at a file the build does not produce
445
+ ### The adapter's default worker url follows the scope
443
446
 
444
- `getRelayWindowMessageHandler`'s default `swUrl` and `SwPortHandler`'s default
445
- worker URL both resolve to `index-sw.js` next to the module. No such file is
446
- built. Pass `swUrl` / `serviceWorkerUrl` explicitly. Constructing a
447
+ Without `serviceWorkerUrl`, `SwPortHandler` (and so `SwHttpAdapter`) uses
448
+ `sw-worker.js` at its scope, the scope resolved against the bundle's url. With
449
+ `scope: "/dist/"` that is the shipped `dist/sw-worker.js`; with `scope: "/"` it
450
+ is `/sw-worker.js`, a loader the host must serve there. Constructing a
447
451
  `SwHttpAdapter` with neither `serviceWorkerUrl` nor `scope` fails with
448
452
  `RangeError: Maximum call stack size exceeded`, because each default is
449
453
  computed from the other.
package/dist/index.js CHANGED
@@ -2794,7 +2794,7 @@ async function callHttpService(request, { key, port }) {
2794
2794
  * call the parent makes on that port is answered with the error, so the
2795
2795
  * parent's `initHttpService` / `callHttpService` reject instead of waiting.
2796
2796
  */
2797
- function getRelayWindowMessageHandler({ swUrl = `${new URL("./index-sw.js", moduleUrl)}`, scopeUrl = `${new URL("../", moduleUrl)}`, timeout } = {}) {
2797
+ function getRelayWindowMessageHandler({ swUrl = `${new URL("./relay-sw.js", moduleUrl)}`, scopeUrl = `${new URL("./", moduleUrl)}`, timeout } = {}) {
2798
2798
  let externalPort;
2799
2799
  return async (ev) => {
2800
2800
  if (ev.data?.type !== "CONNECT") return;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/relay/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAGpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAQ/D,cAAc,wBAAwB,CAAC;AAavC;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,CAAC,EAAE,yBAAyB,GAAG,WAAW,CAU1F;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,aAAa,CAAC,CAEjG;AAgBD,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,aAAa,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,WAAW,EACpB,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,cAAc,GAClC,OAAO,CAAC,MAAM,IAAI,CAAC,CAUrB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,EAChB,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,cAAc,GAC5B,OAAO,CAAC,QAAQ,CAAC,CAInB;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;A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iCAAiC,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAYzD"}
@@ -31,6 +31,7 @@ export declare class SwPortHandler {
31
31
  private _serviceWorkerUrl?;
32
32
  private _serviceWorker?;
33
33
  private _registrationPromise?;
34
+ private _registration?;
34
35
  private _cleanupRegistrations?;
35
36
  constructor(options: SwPortHandlerOptions);
36
37
  get key(): string;
@@ -40,7 +41,7 @@ export declare class SwPortHandler {
40
41
  * own url when one is given, not against this module's: a bundle that is
41
42
  * not an ES module (an IIFE, Theia's frontend) has no `import.meta.url`, and
42
43
  * `new URL(scope, undefined)` threw `Invalid URL` there. Only without a
43
- * worker url does the module's location decide (its default `index-sw.js`
44
+ * worker url does the module's location decide (its default `sw-worker.js`
44
45
  * sits next to it).
45
46
  */
46
47
  get rootUrl(): URL;
@@ -1 +1 @@
1
- {"version":3,"file":"sw-dispatcher.d.ts","sourceRoot":"","sources":["../../src/sw/sw-dispatcher.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,UAAU,WAAW;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;IACvC,OAAO,CAAC,iBAAiB,CAAC,CAAS;IACnC,OAAO,CAAC,cAAc,CAAC,CAAgB;IACvC,OAAO,CAAC,oBAA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AO,CAEjC;IAED,KAAK,IAAI,IAAI,CAgCZ;IAEK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAK1B;IAED,OAAO,CAAC,gBAAgB;YAOV,SAAS;YAgBT,kBAAkB;YAWlB,cAAc;YAOd,gBAAgB;CAY/B"}
package/dist/sw.js CHANGED
@@ -1753,6 +1753,7 @@ var SwPortHandler = class {
1753
1753
  _serviceWorkerUrl;
1754
1754
  _serviceWorker;
1755
1755
  _registrationPromise;
1756
+ _registration;
1756
1757
  _cleanupRegistrations;
1757
1758
  constructor(options) {
1758
1759
  this.options = options;
@@ -1770,7 +1771,7 @@ var SwPortHandler = class {
1770
1771
  * own url when one is given, not against this module's: a bundle that is
1771
1772
  * not an ES module (an IIFE, Theia's frontend) has no `import.meta.url`, and
1772
1773
  * `new URL(scope, undefined)` threw `Invalid URL` there. Only without a
1773
- * worker url does the module's location decide (its default `index-sw.js`
1774
+ * worker url does the module's location decide (its default `sw-worker.js`
1774
1775
  * sits next to it).
1775
1776
  */
1776
1777
  get rootUrl() {
@@ -1779,7 +1780,7 @@ var SwPortHandler = class {
1779
1780
  }
1780
1781
  get serviceWorkerUrl() {
1781
1782
  if (!this._serviceWorkerUrl) {
1782
- const url = this.options.serviceWorkerUrl ? resolveWorkerUrl(this.options.serviceWorkerUrl) : new URL("./index-sw.js", this.rootUrl);
1783
+ const url = this.options.serviceWorkerUrl ? resolveWorkerUrl(this.options.serviceWorkerUrl) : new URL("./sw-worker.js", this.rootUrl);
1783
1784
  this._serviceWorkerUrl = `${url}`;
1784
1785
  }
1785
1786
  return this._serviceWorkerUrl;
@@ -1817,7 +1818,7 @@ var SwPortHandler = class {
1817
1818
  this._cleanupRegistrations = void 0;
1818
1819
  });
1819
1820
  const registration = await navigator.serviceWorker.register(this.serviceWorkerUrl, { scope: this.scope });
1820
- register(() => registration.unregister());
1821
+ this._registration = registration;
1821
1822
  const stopListening = handleChannelCalls(navigator.serviceWorker, "UPDATE_COMMUNICATION_PORT", async (_event, _params, port) => {
1822
1823
  await this._setCommunicationPort(port);
1823
1824
  return this._getRegistrationInfo();
@@ -1834,6 +1835,7 @@ var SwPortHandler = class {
1834
1835
  } catch (error) {
1835
1836
  stopListening();
1836
1837
  this._cleanupRegistrations = void 0;
1838
+ this._registration = void 0;
1837
1839
  this._registrationPromise = void 0;
1838
1840
  throw error;
1839
1841
  }
@@ -1842,11 +1844,12 @@ var SwPortHandler = class {
1842
1844
  }
1843
1845
  async stop() {
1844
1846
  this._cleanupRegistrations?.();
1845
- const registrations = await navigator.serviceWorker.getRegistrations();
1846
- for (const registration of registrations) try {
1847
- await registration.unregister();
1847
+ const registration = this._registration;
1848
+ this._registration = void 0;
1849
+ try {
1850
+ await registration?.unregister();
1848
1851
  } catch (error) {
1849
- console.log("Service Worker registration failed: ", error);
1852
+ console.log("Service Worker unregistration failed: ", error);
1850
1853
  }
1851
1854
  }
1852
1855
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statewalker/webrun-http-browser",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "ServiceWorker-based HTTP server for browsers, with relay and same-origin dispatch modes",
@@ -53,9 +53,9 @@
53
53
  ],
54
54
  "dependencies": {
55
55
  "idb-keyval": "^6.3.0",
56
- "@statewalker/webrun-rpc": "^0.4.3",
56
+ "@statewalker/webrun-http-streams": "^0.2.5",
57
57
  "@statewalker/webrun-streams": "^0.2.2",
58
- "@statewalker/webrun-http-streams": "^0.2.5"
58
+ "@statewalker/webrun-rpc": "^0.4.3"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@biomejs/biome": "^2.5.15",
@@ -135,8 +135,8 @@ export interface RelayWindowHandlerOptions {
135
135
  * parent's `initHttpService` / `callHttpService` reject instead of waiting.
136
136
  */
137
137
  export function getRelayWindowMessageHandler({
138
- swUrl = `${new URL("./index-sw.js", moduleUrl)}`,
139
- scopeUrl = `${new URL("../", moduleUrl)}`,
138
+ swUrl = `${new URL("./relay-sw.js", moduleUrl)}`,
139
+ scopeUrl = `${new URL("./", moduleUrl)}`,
140
140
  timeout,
141
141
  }: RelayWindowHandlerOptions = {}): (ev: MessageEvent) => Promise<void> {
142
142
  let externalPort: MessagePort | undefined;
@@ -44,6 +44,7 @@ export class SwPortHandler {
44
44
  private _serviceWorkerUrl?: string;
45
45
  private _serviceWorker?: ServiceWorker;
46
46
  private _registrationPromise?: Promise<void>;
47
+ private _registration?: ServiceWorkerRegistration;
47
48
  private _cleanupRegistrations?: () => void;
48
49
 
49
50
  constructor(options: SwPortHandlerOptions) {
@@ -65,7 +66,7 @@ export class SwPortHandler {
65
66
  * own url when one is given, not against this module's: a bundle that is
66
67
  * not an ES module (an IIFE, Theia's frontend) has no `import.meta.url`, and
67
68
  * `new URL(scope, undefined)` threw `Invalid URL` there. Only without a
68
- * worker url does the module's location decide (its default `index-sw.js`
69
+ * worker url does the module's location decide (its default `sw-worker.js`
69
70
  * sits next to it).
70
71
  */
71
72
  get rootUrl(): URL {
@@ -82,7 +83,7 @@ export class SwPortHandler {
82
83
  // use — `"/sw-worker.js"` — threw a bare `Invalid URL` naming
83
84
  // neither the option nor the value.
84
85
  resolveWorkerUrl(this.options.serviceWorkerUrl)
85
- : new URL("./index-sw.js", this.rootUrl);
86
+ : new URL("./sw-worker.js", this.rootUrl);
86
87
  this._serviceWorkerUrl = `${url}`;
87
88
  }
88
89
  return this._serviceWorkerUrl;
@@ -133,7 +134,7 @@ export class SwPortHandler {
133
134
  const registration = await navigator.serviceWorker.register(this.serviceWorkerUrl, {
134
135
  scope: this.scope,
135
136
  });
136
- register(() => registration.unregister());
137
+ this._registration = registration;
137
138
 
138
139
  const stopListening = handleChannelCalls(
139
140
  navigator.serviceWorker,
@@ -170,6 +171,7 @@ export class SwPortHandler {
170
171
  // that is not controlled, and other pages may be using the worker.
171
172
  stopListening();
172
173
  this._cleanupRegistrations = undefined;
174
+ this._registration = undefined;
173
175
  this._registrationPromise = undefined;
174
176
  throw error;
175
177
  }
@@ -180,13 +182,12 @@ export class SwPortHandler {
180
182
 
181
183
  async stop(): Promise<void> {
182
184
  this._cleanupRegistrations?.();
183
- const registrations = await navigator.serviceWorker.getRegistrations();
184
- for (const registration of registrations) {
185
- try {
186
- await registration.unregister();
187
- } catch (error) {
188
- console.log("Service Worker registration failed: ", error);
189
- }
185
+ const registration = this._registration;
186
+ this._registration = undefined;
187
+ try {
188
+ await registration?.unregister();
189
+ } catch (error) {
190
+ console.log("Service Worker unregistration failed: ", error);
190
191
  }
191
192
  }
192
193
  }