| 1 | diff --git a/internal/webui/private-services.js b/internal/webui/private-services.js |
| 2 | index 9a0e8e4..46cbc96 100644 |
| 3 | --- a/internal/webui/private-services.js |
| 4 | +++ b/internal/webui/private-services.js |
| 5 | @@ -194,5 +194,8 @@ |
| 6 | }); |
| 7 | window.tiny = window.tiny || {}; |
| 8 | window.tiny.files = {...window.tiny.files, privateServices: api}; |
| 9 | - customElements.define("private-services", PrivateServices); |
| 10 | + // In-place navigation can request this bundle after a page already loaded |
| 11 | + // it. Keep the browser's one-definition rule intact while refreshing the |
| 12 | + // shared API above. |
| 13 | + if (!customElements.get("private-services")) customElements.define("private-services", PrivateServices); |
| 14 | })(); |
| 15 | diff --git a/scripts/private-services.test.mjs b/scripts/private-services.test.mjs |
| 16 | index a2da3d3..be65319 100644 |
| 17 | --- a/scripts/private-services.test.mjs |
| 18 | +++ b/scripts/private-services.test.mjs |
| 19 | @@ -6,10 +6,11 @@ import vm from "node:vm"; |
| 20 | const shared = await readFile(new URL("../internal/webui/tiny.js", import.meta.url), "utf8"); |
| 21 | const source = await readFile(new URL("../internal/webui/private-services.js", import.meta.url), "utf8"); |
| 22 | class Element {} |
| 23 | +const definitions = new Map(); |
| 24 | const sandbox = { |
| 25 | URL, TextEncoder, HTMLElement: Element, |
| 26 | document: {}, Response, |
| 27 | - customElements: {define() {}}, |
| 28 | + customElements: {define(name, value) { if (definitions.has(name)) throw Error("duplicate definition"); definitions.set(name, value); }, get(name) { return definitions.get(name); }}, |
| 29 | tinySigner: { |
| 30 | getPublicKey: async () => "a".repeat(64), |
| 31 | nip44Encrypt: async (_pubkey, value) => "enc:" + value, |
| 32 | @@ -23,6 +24,11 @@ sandbox.window = sandbox; |
| 33 | vm.runInNewContext(shared + source, sandbox); |
| 34 | const api = sandbox.tiny.files.privateServices; |
| 35 | |
| 36 | +test("can be evaluated again after in-place navigation", async () => { |
| 37 | + assert.doesNotThrow(() => vm.runInNewContext(source, sandbox)); |
| 38 | + assert.equal(definitions.size, 1); |
| 39 | +}); |
| 40 | + |
| 41 | test("accepts tenant paths while rejecting unsafe relay URLs", () => { |
| 42 | assert.equal(api.validURL("wss://Relay.Example/r/Private"), true); |
| 43 | assert.equal(api.canonicalURL("wss://Relay.Example/r/Private/"), "wss://relay.example/r/Private"); |