1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Freenet notification service worker.
//
// Why this exists: mobile browsers (Chrome / Firefox on Android) do NOT support
// the page-level `new Notification(...)` constructor — it throws "Illegal
// constructor. Use ServiceWorkerRegistration.showNotification() instead". The
// ONLY way to show a web notification on mobile is via a service worker's
// showNotification(). Desktop supports both. So the gateway shell
// (shell_bridge.js) registers this worker and calls
// registration.showNotification() so notifications work on mobile as well as
// desktop.
//
// This worker is deliberately minimal:
// - It has NO `fetch` handler, so it NEVER intercepts, caches, or alters any
// network request. Registering it changes nothing about how pages, the
// WASM app, or the node WebSocket load — it exists only to own
// showNotification() and to route notification clicks back to the shell.
// - It shows nothing on its own: the shell decides when to call
// showNotification(), applying the browser-permission + per-contract
// consent + rate-limit gates in shell_bridge.js. This worker is not a push
// endpoint (there is no `push` handler); it only displays notifications the
// shell explicitly asks for while a shell page is open.
// - Access worker globals through `self.` (self.clients, self.skipWaiting) so
// the file lints under the browser eslint env without a service-worker env.
'use strict';
self.;
self.;
// Derive a contract's routing prefix (the FIRST /v[12]/contract/web/<key>/
// segment) from a URL, and select the open window that belongs to it. Anchoring
// on the FIRST segment — the contract its shell actually serves; the shell nav
// proxy pins the leading key — and comparing for EQUALITY is what keeps a click
// for contract A from focusing contract B's tab or leaking A's room tag into it
// (and off the gateway dashboard). A plain substring test would be fooled by a
// crafted same-contract subpath that merely CONTAINS another contract's segment
// (e.g. .../web/BBB/v1/contract/web/AAA/, reachable via the nav proxy). Returns
// null when no open window matches — the caller then opens a fresh window rather
// than handing the tag to an unrelated tab.
//
// notify-pick-client:BEGIN — pure; extracted verbatim between these markers and
// unit-tested by notify_sw.test.mjs. Keep it pure (params/locals only).
// notify-pick-client:END
// A notification was clicked. The click fires HERE (in the worker), not in the
// page, so we focus the originating contract's shell window and hand it the
// click; the shell forwards it to the sandboxed iframe as `notification_click`
// (see shell_bridge.js), which routes the app to the right room. This mirrors
// the page-level `n.onclick` path used on desktop when no service worker is
// active.
self.;