@zerogpu/browser-extension-sdk 0.2.2 → 0.2.3
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/bin/zerogpu.mjs +155 -27
- package/dist/assets/zerogpu-assets.json +4 -2
- package/dist/extension/zerogpu-background.js +365 -0
- package/dist/extension/zerogpu-background.js.map +1 -0
- package/dist/extension/zerogpu-offscreen.js +112 -2
- package/dist/extension/zerogpu-offscreen.js.map +1 -1
- package/dist/extension/zerogpu-settings-link.js +160 -0
- package/dist/extension/zerogpu-settings-link.js.map +1 -0
- package/dist/manifest.json +5 -5
- package/dist/types/extension/background.d.ts +71 -0
- package/dist/types/extension/consent.d.ts +62 -0
- package/dist/types/extension/settings-link.d.ts +14 -0
- package/dist/v/{zerogpu-browser-sdk.1d7d5ce752ee.umd.js → zerogpu-browser-sdk.85b3f7e3cc11.umd.js} +3 -3
- package/dist/v/{zerogpu-browser-sdk.1d7d5ce752ee.umd.js.map → zerogpu-browser-sdk.85b3f7e3cc11.umd.js.map} +1 -1
- package/dist/zerogpu-browser-sdk.cjs +2 -2
- package/dist/zerogpu-browser-sdk.esm.js +2 -2
- package/dist/zerogpu-browser-sdk.umd.js +2 -2
- package/docs/extension-developer-guide.md +178 -3
- package/package.json +7 -1
package/bin/zerogpu.mjs
CHANGED
|
@@ -27,10 +27,17 @@ const pkgRoot = path.resolve(__dirname, '..');
|
|
|
27
27
|
const distDir = path.join(pkgRoot, 'dist');
|
|
28
28
|
const distAssets = path.join(distDir, 'assets');
|
|
29
29
|
const distOffscreen = path.join(distDir, 'extension', 'zerogpu-offscreen.js');
|
|
30
|
+
const distBackground = path.join(distDir, 'extension', 'zerogpu-background.js');
|
|
31
|
+
const distSettingsLink = path.join(distDir, 'extension', 'zerogpu-settings-link.js');
|
|
30
32
|
|
|
31
33
|
const HOST_PERMISSIONS = ['<all_urls>'];
|
|
32
34
|
const REQUIRED_CSP = "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'";
|
|
33
35
|
|
|
36
|
+
// Origins allowed to reach the extension via chrome.runtime.sendMessage, i.e.
|
|
37
|
+
// the ZeroGPU-hosted end-user settings page where a user can turn sharing off.
|
|
38
|
+
// Must stay in step with DEFAULT_ALLOWED_ORIGINS in src/extension/background.ts.
|
|
39
|
+
const EXTERNALLY_CONNECTABLE_MATCHES = ['https://*.zerogpu.ai/*'];
|
|
40
|
+
|
|
34
41
|
const c = {
|
|
35
42
|
ok: (s) => `\x1b[32m${s}\x1b[0m`,
|
|
36
43
|
warn: (s) => `\x1b[33m${s}\x1b[0m`,
|
|
@@ -66,7 +73,12 @@ const parseFlags = (argv) => {
|
|
|
66
73
|
};
|
|
67
74
|
|
|
68
75
|
const ensureDistPresent = () => {
|
|
69
|
-
if (
|
|
76
|
+
if (
|
|
77
|
+
!existsSync(distOffscreen) ||
|
|
78
|
+
!existsSync(distBackground) ||
|
|
79
|
+
!existsSync(distSettingsLink) ||
|
|
80
|
+
!existsSync(distAssets)
|
|
81
|
+
) {
|
|
70
82
|
die(
|
|
71
83
|
'Built SDK assets not found. Reinstall @zerogpu/browser-extension-sdk (its dist/ ships the runtime).'
|
|
72
84
|
);
|
|
@@ -82,6 +94,9 @@ const vendor = (outDir) => {
|
|
|
82
94
|
|
|
83
95
|
// The offscreen host bundle (contains the SDK itself).
|
|
84
96
|
cpSync(distOffscreen, path.join(target, 'zerogpu-offscreen.js'));
|
|
97
|
+
// The service-worker consent bridge (tiny; no SDK runtime inside).
|
|
98
|
+
cpSync(distBackground, path.join(target, 'zerogpu-background.js'));
|
|
99
|
+
cpSync(distSettingsLink, path.join(target, 'zerogpu-settings-link.js'));
|
|
85
100
|
// All pinned runtime assets (transformers + ONNX wasm, wllama + wasm, manifest).
|
|
86
101
|
cpSync(distAssets, target, { recursive: true });
|
|
87
102
|
|
|
@@ -129,32 +144,76 @@ initZeroGpuOffscreen({
|
|
|
129
144
|
});
|
|
130
145
|
`;
|
|
131
146
|
|
|
132
|
-
const BACKGROUND_JS = `// ZeroGPU
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
await creating;
|
|
152
|
-
creating = null;
|
|
153
|
-
}
|
|
147
|
+
const BACKGROUND_JS = `// ZeroGPU service worker. Owns the offscreen document where the SDK runs, and
|
|
148
|
+
// gates it on the end user's choice: while they are opted out, the document is
|
|
149
|
+
// never created, so the decision survives browser restarts. Merge into your
|
|
150
|
+
// existing service worker if you already have one.
|
|
151
|
+
importScripts("vendor/zerogpu/zerogpu-background.js");
|
|
152
|
+
|
|
153
|
+
// Installs the consent bridge: it answers the ZeroGPU-hosted settings page
|
|
154
|
+
// (via externally_connectable), answers your own popup/options page, reacts to
|
|
155
|
+
// storage changes, and starts the SDK on install/startup only if opted in.
|
|
156
|
+
ZeroGpuBackground.registerZeroGpuConsentBridge({
|
|
157
|
+
offscreenPath: "offscreen.html"
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Read or change the choice from your own UI:
|
|
161
|
+
// await ZeroGpuBackground.getZeroGpuConsent() -> { optedIn, updatedAt, source }
|
|
162
|
+
// await ZeroGpuBackground.setZeroGpuConsent(false) -> stops the SDK now
|
|
163
|
+
// ZeroGpuBackground.buildZeroGpuSettingsUrl({ extensionId: chrome.runtime.id })
|
|
164
|
+
`;
|
|
154
165
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
166
|
+
const OPTIONS_HTML = `<!DOCTYPE html>
|
|
167
|
+
<html>
|
|
168
|
+
<head>
|
|
169
|
+
<meta charset="utf-8" />
|
|
170
|
+
<title>Settings</title>
|
|
171
|
+
<style>
|
|
172
|
+
body { font-family: system-ui, sans-serif; margin: 2rem; max-width: 34rem; line-height: 1.5; }
|
|
173
|
+
.row { display: flex; align-items: flex-start; gap: .75rem; margin-top: 1.5rem; }
|
|
174
|
+
.muted { color: #666; font-size: .875rem; }
|
|
175
|
+
</style>
|
|
176
|
+
</head>
|
|
177
|
+
<body>
|
|
178
|
+
<h1>Resource sharing</h1>
|
|
179
|
+
<p class="muted">
|
|
180
|
+
This app can use some of your device's free or spare resources, such as
|
|
181
|
+
unused computing power and network bandwidth. You can turn this off at any
|
|
182
|
+
time.
|
|
183
|
+
</p>
|
|
184
|
+
<div class="row">
|
|
185
|
+
<input type="checkbox" id="zerogpu-opt-in" />
|
|
186
|
+
<label for="zerogpu-opt-in">Allow this app to use my device's spare resources</label>
|
|
187
|
+
</div>
|
|
188
|
+
<p class="muted" id="zerogpu-status"></p>
|
|
189
|
+
<script src="options.js"></script>
|
|
190
|
+
</body>
|
|
191
|
+
</html>
|
|
192
|
+
`;
|
|
193
|
+
|
|
194
|
+
const OPTIONS_JS = `// Reads and writes the ZeroGPU consent flag through the service-worker bridge.
|
|
195
|
+
const box = document.getElementById("zerogpu-opt-in");
|
|
196
|
+
const status = document.getElementById("zerogpu-status");
|
|
197
|
+
|
|
198
|
+
const render = (consent) => {
|
|
199
|
+
box.checked = !!consent?.optedIn;
|
|
200
|
+
status.textContent = consent?.updatedAt
|
|
201
|
+
? \`Last changed \${new Date(consent.updatedAt).toLocaleString()}.\`
|
|
202
|
+
: "";
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
chrome.runtime.sendMessage({ type: "zerogpu:getConsent" }, (res) => {
|
|
206
|
+
if (res?.ok) render(res.consent);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
box.addEventListener("change", () => {
|
|
210
|
+
chrome.runtime.sendMessage(
|
|
211
|
+
{ type: "zerogpu:setConsent", optedIn: box.checked },
|
|
212
|
+
(res) => {
|
|
213
|
+
if (res?.ok) render(res.consent);
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
});
|
|
158
217
|
`;
|
|
159
218
|
|
|
160
219
|
const uniqueMerge = (existing, additions) => {
|
|
@@ -181,6 +240,17 @@ const patchManifest = (dir) => {
|
|
|
181
240
|
if (!manifest.background) {
|
|
182
241
|
manifest.background = { service_worker: 'background.js' };
|
|
183
242
|
}
|
|
243
|
+
// Lets the ZeroGPU-hosted settings page message this extension so an end user
|
|
244
|
+
// can turn sharing off. Merged, never replaced — a host may already allow its
|
|
245
|
+
// own site. No content script and no extra host permission needed.
|
|
246
|
+
manifest.externally_connectable = manifest.externally_connectable || {};
|
|
247
|
+
manifest.externally_connectable.matches = uniqueMerge(
|
|
248
|
+
manifest.externally_connectable.matches,
|
|
249
|
+
EXTERNALLY_CONNECTABLE_MATCHES
|
|
250
|
+
);
|
|
251
|
+
if (!manifest.options_page && !manifest.options_ui) {
|
|
252
|
+
manifest.options_ui = { page: 'options.html', open_in_tab: true };
|
|
253
|
+
}
|
|
184
254
|
writeFileSync(file, JSON.stringify(manifest, null, 2) + '\n');
|
|
185
255
|
log(c.ok('✓ Patched manifest.json (permissions, CSP, host permissions)'));
|
|
186
256
|
};
|
|
@@ -202,16 +272,35 @@ const init = (dir) => {
|
|
|
202
272
|
scaffoldFile(root, 'offscreen.html', OFFSCREEN_HTML);
|
|
203
273
|
scaffoldFile(root, 'offscreen.js', OFFSCREEN_JS);
|
|
204
274
|
scaffoldFile(root, 'background.js', BACKGROUND_JS);
|
|
275
|
+
scaffoldFile(root, 'options.html', OPTIONS_HTML);
|
|
276
|
+
scaffoldFile(root, 'options.js', OPTIONS_JS);
|
|
205
277
|
patchManifest(root);
|
|
206
278
|
log('');
|
|
207
279
|
log(c.ok('ZeroGPU integrated.') + ' Next:');
|
|
208
280
|
log(' 1. Put your operator key in offscreen.js (REPLACE_WITH_YOUR_OPERATOR_KEY).');
|
|
209
281
|
log(' 2. Load the extension unpacked — it registers automatically on startup.');
|
|
210
282
|
log(' 3. Re-run ' + c.dim('npx zerogpu vendor') + ' in your build to stay up to date.');
|
|
283
|
+
log(' 4. Give users the opt-out link (options.html ships one, or link them to');
|
|
284
|
+
log(' ' + c.dim('https://zerogpu.ai/extension-settings?browser=chrome&extension_id=<your id>') + ').');
|
|
211
285
|
};
|
|
212
286
|
|
|
213
287
|
// --- doctor ------------------------------------------------------------------
|
|
214
288
|
|
|
289
|
+
/**
|
|
290
|
+
* A mention is not a call. Block comments and whole-line `//` comments are
|
|
291
|
+
* dropped first, so a commented-out invocation — the shape someone leaves
|
|
292
|
+
* behind while debugging — is not read as wired up. Mid-line `//` is left
|
|
293
|
+
* alone: stripping it would eat the `//` of any URL in a string literal.
|
|
294
|
+
*/
|
|
295
|
+
const callsConsentBridge = (source) => {
|
|
296
|
+
const code = source
|
|
297
|
+
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
298
|
+
.split('\n')
|
|
299
|
+
.filter((line) => !/^\s*\/\//.test(line))
|
|
300
|
+
.join('\n');
|
|
301
|
+
return /registerZeroGpuConsentBridge\s*\(/.test(code);
|
|
302
|
+
};
|
|
303
|
+
|
|
215
304
|
const doctor = (dir) => {
|
|
216
305
|
const root = path.resolve(process.cwd(), dir || '.');
|
|
217
306
|
const vendorDir = path.join(root, 'vendor', 'zerogpu');
|
|
@@ -243,10 +332,11 @@ const doctor = (dir) => {
|
|
|
243
332
|
}
|
|
244
333
|
|
|
245
334
|
const manifestFile = path.join(root, 'manifest.json');
|
|
335
|
+
let manifest = null;
|
|
246
336
|
if (!existsSync(manifestFile)) {
|
|
247
337
|
log(c.warn('! manifest.json not found.'));
|
|
248
338
|
} else {
|
|
249
|
-
|
|
339
|
+
manifest = JSON.parse(readFileSync(manifestFile, 'utf8'));
|
|
250
340
|
const csp = manifest.content_security_policy?.extension_pages || '';
|
|
251
341
|
if (!csp.includes("'wasm-unsafe-eval'")) {
|
|
252
342
|
log(c.err("✗ CSP extension_pages missing 'wasm-unsafe-eval'"));
|
|
@@ -263,6 +353,44 @@ const doctor = (dir) => {
|
|
|
263
353
|
if (!hosts.some((h) => h === '<all_urls>' || h.includes('zerogpu.ai'))) {
|
|
264
354
|
log(c.warn('! No zerogpu.ai host permission found (register/WS may be blocked).'));
|
|
265
355
|
}
|
|
356
|
+
// Without this the hosted settings page cannot reach the extension, so an
|
|
357
|
+
// end user has no way to opt out from the web.
|
|
358
|
+
const connectable = manifest.externally_connectable?.matches || [];
|
|
359
|
+
if (!connectable.some((m) => m.includes('zerogpu.ai'))) {
|
|
360
|
+
log(
|
|
361
|
+
c.err(
|
|
362
|
+
'✗ manifest externally_connectable.matches missing a zerogpu.ai entry (end users cannot opt out from the settings page)'
|
|
363
|
+
)
|
|
364
|
+
);
|
|
365
|
+
problems += 1;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Check the worker the manifest actually loads. An extension that already had
|
|
370
|
+
// a service worker keeps its own path, and that merged file — not a root
|
|
371
|
+
// background.js — is where the bridge has to be registered.
|
|
372
|
+
const workerPath = manifest?.background?.service_worker || 'background.js';
|
|
373
|
+
const backgroundFile = path.join(root, workerPath);
|
|
374
|
+
if (!existsSync(backgroundFile)) {
|
|
375
|
+
log(c.err(`✗ Service worker not found: ${workerPath}`));
|
|
376
|
+
problems += 1;
|
|
377
|
+
} else {
|
|
378
|
+
const background = readFileSync(backgroundFile, 'utf8');
|
|
379
|
+
if (!callsConsentBridge(background)) {
|
|
380
|
+
// Say which of the two it is — "does not call" reads like a doctor bug to
|
|
381
|
+
// someone who can see the name right there in their file.
|
|
382
|
+
const commentedOut = background.includes('registerZeroGpuConsentBridge');
|
|
383
|
+
log(
|
|
384
|
+
c.warn(
|
|
385
|
+
`! ${workerPath} ${
|
|
386
|
+
commentedOut
|
|
387
|
+
? 'mentions registerZeroGpuConsentBridge but never calls it'
|
|
388
|
+
: 'does not call registerZeroGpuConsentBridge'
|
|
389
|
+
} — the SDK will start regardless of the user's choice.`
|
|
390
|
+
)
|
|
391
|
+
);
|
|
392
|
+
problems += 1;
|
|
393
|
+
}
|
|
266
394
|
}
|
|
267
395
|
|
|
268
396
|
if (problems === 0) {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"sdkVersion": "0.2.
|
|
2
|
+
"sdkVersion": "0.2.3+38ce04b",
|
|
3
3
|
"channel": "official",
|
|
4
4
|
"transformersVersion": "2.17.2",
|
|
5
5
|
"wllamaVersion": "2.3.5",
|
|
6
6
|
"files": [
|
|
7
7
|
"zerogpu-offscreen.js",
|
|
8
|
+
"zerogpu-background.js",
|
|
9
|
+
"zerogpu-settings-link.js",
|
|
8
10
|
"transformers.min.js",
|
|
9
11
|
"ort-wasm.wasm",
|
|
10
12
|
"ort-wasm-simd.wasm",
|
|
@@ -14,5 +16,5 @@
|
|
|
14
16
|
"wllama/single-thread/wllama.wasm",
|
|
15
17
|
"wllama/multi-thread/wllama.wasm"
|
|
16
18
|
],
|
|
17
|
-
"builtAt": "2026-08-
|
|
19
|
+
"builtAt": "2026-08-31T20:12:36.624Z"
|
|
18
20
|
}
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
var ZeroGpuBackground = (function (exports) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ZeroGPU "extension kit" — end-user consent store.
|
|
6
|
+
*
|
|
7
|
+
* An end user must be able to stop the SDK on their own device, and have that
|
|
8
|
+
* stick across browser restarts. That decision lives in `chrome.storage.local`
|
|
9
|
+
* rather than the offscreen document's `localStorage`, because the service
|
|
10
|
+
* worker has to read it *before* deciding whether to create the offscreen
|
|
11
|
+
* document at all — and it has no access to that document's storage.
|
|
12
|
+
*
|
|
13
|
+
* Enforcement is entirely client-side: opting out stops the device connecting.
|
|
14
|
+
* Nothing is deregistered server-side.
|
|
15
|
+
*/
|
|
16
|
+
/** Single `chrome.storage.local` key holding the whole record. */
|
|
17
|
+
const ZEROGPU_CONSENT_KEY = 'zerogpu:consent';
|
|
18
|
+
/**
|
|
19
|
+
* Opted IN until told otherwise, which preserves the behaviour every already
|
|
20
|
+
* shipped extension has today: adding this module must not silently stop
|
|
21
|
+
* existing installs. The hosted settings page is what turns it off.
|
|
22
|
+
*/
|
|
23
|
+
const DEFAULT_CONSENT = {
|
|
24
|
+
optedIn: true,
|
|
25
|
+
updatedAt: null,
|
|
26
|
+
source: 'default'
|
|
27
|
+
};
|
|
28
|
+
const getLocalStorageArea = () => typeof chrome !== 'undefined' ? chrome?.storage?.local : undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Coerce whatever is in storage into a usable record. Anything unexpected —
|
|
31
|
+
* a partial write, a value from a future version, a corrupted entry — falls
|
|
32
|
+
* back to the default rather than throwing: a consent read must never be the
|
|
33
|
+
* reason the SDK fails to start.
|
|
34
|
+
*/
|
|
35
|
+
const normalize = (raw) => {
|
|
36
|
+
if (!raw || typeof raw !== 'object')
|
|
37
|
+
return DEFAULT_CONSENT;
|
|
38
|
+
const value = raw;
|
|
39
|
+
if (typeof value.optedIn !== 'boolean')
|
|
40
|
+
return DEFAULT_CONSENT;
|
|
41
|
+
return {
|
|
42
|
+
optedIn: value.optedIn,
|
|
43
|
+
updatedAt: typeof value.updatedAt === 'string' ? value.updatedAt : null,
|
|
44
|
+
source: value.source === 'extension' || value.source === 'settings-page' || value.source === 'default'
|
|
45
|
+
? value.source
|
|
46
|
+
: 'default'
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/** Read the stored decision, or the default when nothing has been stored. */
|
|
50
|
+
const getZeroGpuConsent = async () => {
|
|
51
|
+
const area = getLocalStorageArea();
|
|
52
|
+
if (!area)
|
|
53
|
+
return DEFAULT_CONSENT;
|
|
54
|
+
try {
|
|
55
|
+
const stored = await area.get(ZEROGPU_CONSENT_KEY);
|
|
56
|
+
return normalize(stored?.[ZEROGPU_CONSENT_KEY]);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// A blocked or full storage area must not keep the SDK from starting.
|
|
60
|
+
return DEFAULT_CONSENT;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
/** Convenience for the common gate: "may the SDK run right now?" */
|
|
64
|
+
const isZeroGpuOptedIn = async () => (await getZeroGpuConsent()).optedIn;
|
|
65
|
+
/**
|
|
66
|
+
* Record a decision. The write is what drives everything else — the background
|
|
67
|
+
* bridge listens on `chrome.storage.onChanged` and starts or stops the SDK in
|
|
68
|
+
* response, so no caller needs to do both.
|
|
69
|
+
*/
|
|
70
|
+
const setZeroGpuConsent = async (optedIn, source = 'extension') => {
|
|
71
|
+
const next = { optedIn, updatedAt: new Date().toISOString(), source };
|
|
72
|
+
const area = getLocalStorageArea();
|
|
73
|
+
// Deliberately not symmetric with the read above. A read fails open so the SDK
|
|
74
|
+
// can still start; a write must fail loudly, because reporting success for a
|
|
75
|
+
// decision that was never stored would tell the user their choice is saved
|
|
76
|
+
// when it would not survive a restart. `handleMessage` turns this into
|
|
77
|
+
// `{ ok: false }`, exactly as it already does for a rejecting `area.set`.
|
|
78
|
+
if (!area)
|
|
79
|
+
throw new Error('chrome.storage.local unavailable — consent was not saved');
|
|
80
|
+
await area.set({ [ZEROGPU_CONSENT_KEY]: next });
|
|
81
|
+
return next;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Subscribe to consent changes from any extension context (the hosted settings
|
|
85
|
+
* page writing through the service worker, the options page, another window).
|
|
86
|
+
* Returns an unsubscribe function.
|
|
87
|
+
*/
|
|
88
|
+
const onZeroGpuConsentChanged = (listener) => {
|
|
89
|
+
const onChanged = typeof chrome !== 'undefined' ? chrome?.storage?.onChanged : undefined;
|
|
90
|
+
if (!onChanged?.addListener)
|
|
91
|
+
return () => { };
|
|
92
|
+
const handler = (changes, areaName) => {
|
|
93
|
+
if (areaName !== 'local')
|
|
94
|
+
return;
|
|
95
|
+
const change = changes?.[ZEROGPU_CONSENT_KEY];
|
|
96
|
+
if (!change)
|
|
97
|
+
return;
|
|
98
|
+
listener(normalize(change.newValue));
|
|
99
|
+
};
|
|
100
|
+
onChanged.addListener(handler);
|
|
101
|
+
return () => onChanged.removeListener?.(handler);
|
|
102
|
+
};
|
|
103
|
+
/** Default host for the ZeroGPU-hosted end-user settings page. */
|
|
104
|
+
const ZEROGPU_SETTINGS_BASE_URL = 'https://zerogpu.ai/extension-settings';
|
|
105
|
+
/**
|
|
106
|
+
* Build the end-user settings URL for this extension. Deliberately carries no
|
|
107
|
+
* operator key: the page only needs the extension id to address a message, and
|
|
108
|
+
* keeping keys out is what lets the page stay backend-free.
|
|
109
|
+
*/
|
|
110
|
+
const buildZeroGpuSettingsUrl = ({ extensionId, appName, baseUrl = ZEROGPU_SETTINGS_BASE_URL, debug = false }) => {
|
|
111
|
+
const url = new URL(baseUrl);
|
|
112
|
+
url.searchParams.set('browser', 'chrome');
|
|
113
|
+
url.searchParams.set('extension_id', extensionId);
|
|
114
|
+
if (appName)
|
|
115
|
+
url.searchParams.set('app_name', appName);
|
|
116
|
+
if (debug)
|
|
117
|
+
url.searchParams.set('debug_mode', 'true');
|
|
118
|
+
return url.toString();
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* ZeroGPU "extension kit" — service-worker consent bridge.
|
|
123
|
+
*
|
|
124
|
+
* This is the piece that makes an end user's opt-out real. It owns the offscreen
|
|
125
|
+
* document's lifecycle and refuses to create it while the user is opted out, so
|
|
126
|
+
* the decision survives browser restarts rather than lasting only as long as the
|
|
127
|
+
* current document.
|
|
128
|
+
*
|
|
129
|
+
* It also exposes a deliberately tiny message vocabulary to the ZeroGPU-hosted
|
|
130
|
+
* settings page via `chrome.runtime.onMessageExternal`, so a user can flip the
|
|
131
|
+
* switch from a normal web page (the Mellowtel-style flow) without the host
|
|
132
|
+
* extension needing a content script.
|
|
133
|
+
*
|
|
134
|
+
* Built as an IIFE (`dist/extension/zerogpu-background.js`) exposing
|
|
135
|
+
* `self.ZeroGpuBackground`, NOT as an ES module: the scaffolded service worker
|
|
136
|
+
* is a classic worker, and hosts with an existing worker are told to
|
|
137
|
+
* `importScripts(...)` it. Shipping ESM would force `"type": "module"` onto
|
|
138
|
+
* every host extension and break their existing service-worker code.
|
|
139
|
+
*/
|
|
140
|
+
/** The three messages the bridge answers. Nothing here can start inference,
|
|
141
|
+
* read device data, or reach the model store — by design. */
|
|
142
|
+
const ZEROGPU_BRIDGE_MESSAGES = {
|
|
143
|
+
ping: 'zerogpu:ping',
|
|
144
|
+
getConsent: 'zerogpu:getConsent',
|
|
145
|
+
setConsent: 'zerogpu:setConsent'
|
|
146
|
+
};
|
|
147
|
+
/** Matches the offscreen document's own protocol (offscreen.ts). */
|
|
148
|
+
const OFFSCREEN_DISABLE_MESSAGE = 'zerogpu:disable';
|
|
149
|
+
/** Origins allowed to talk to the extension. Must stay in step with the
|
|
150
|
+
* `externally_connectable.matches` entry the CLI writes into manifest.json. */
|
|
151
|
+
const DEFAULT_ALLOWED_ORIGINS = ['https://zerogpu.ai', 'https://www.zerogpu.ai'];
|
|
152
|
+
const DEFAULT_OFFSCREEN_PATH = 'offscreen.html';
|
|
153
|
+
const getChrome = () => (typeof chrome !== 'undefined' ? chrome : undefined);
|
|
154
|
+
/** Serialises concurrent createDocument calls — Chrome rejects a second one
|
|
155
|
+
* while the first is still in flight. */
|
|
156
|
+
let creating = null;
|
|
157
|
+
const resolveOffscreenUrl = (path) => {
|
|
158
|
+
const runtime = getChrome()?.runtime;
|
|
159
|
+
return runtime?.getURL ? runtime.getURL(path) : path;
|
|
160
|
+
};
|
|
161
|
+
const hasOffscreenDocument = async (path) => {
|
|
162
|
+
const runtime = getChrome()?.runtime;
|
|
163
|
+
if (!runtime?.getContexts)
|
|
164
|
+
return false;
|
|
165
|
+
try {
|
|
166
|
+
const contexts = await runtime.getContexts({
|
|
167
|
+
contextTypes: ['OFFSCREEN_DOCUMENT'],
|
|
168
|
+
documentUrls: [resolveOffscreenUrl(path)]
|
|
169
|
+
});
|
|
170
|
+
return Array.isArray(contexts) && contexts.length > 0;
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Create the offscreen document if the user is opted in and it isn't already
|
|
178
|
+
* there. The consent check lives here rather than at the call sites so that
|
|
179
|
+
* every path into starting the SDK is gated by construction.
|
|
180
|
+
*/
|
|
181
|
+
const ensureZeroGpuOffscreen = async (options = {}) => {
|
|
182
|
+
const path = options.offscreenPath ?? DEFAULT_OFFSCREEN_PATH;
|
|
183
|
+
const api = getChrome();
|
|
184
|
+
if (!api?.offscreen?.createDocument)
|
|
185
|
+
return false;
|
|
186
|
+
if (!(await getZeroGpuConsent()).optedIn)
|
|
187
|
+
return false;
|
|
188
|
+
if (await hasOffscreenDocument(path))
|
|
189
|
+
return true;
|
|
190
|
+
if (!creating) {
|
|
191
|
+
creating = api.offscreen
|
|
192
|
+
.createDocument({
|
|
193
|
+
url: path,
|
|
194
|
+
reasons: options.offscreenReasons ?? ['WORKERS'],
|
|
195
|
+
justification: options.justification ?? 'Run the ZeroGPU SDK, which requires a window/DOM context.'
|
|
196
|
+
})
|
|
197
|
+
.finally(() => {
|
|
198
|
+
creating = null;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
await creating;
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
// A racing create from another event can land first; that is a success.
|
|
207
|
+
return hasOffscreenDocument(path);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Stop the SDK: ask the offscreen document to run its ordered shutdown (close
|
|
212
|
+
* the socket, flush telemetry, dispose adapters, mark a clean exit), then tear
|
|
213
|
+
* the document down so nothing restarts inside it.
|
|
214
|
+
*/
|
|
215
|
+
const stopZeroGpuOffscreen = async (options = {}) => {
|
|
216
|
+
const path = options.offscreenPath ?? DEFAULT_OFFSCREEN_PATH;
|
|
217
|
+
const api = getChrome();
|
|
218
|
+
if (!api?.offscreen?.closeDocument)
|
|
219
|
+
return;
|
|
220
|
+
if (!(await hasOffscreenDocument(path)))
|
|
221
|
+
return;
|
|
222
|
+
try {
|
|
223
|
+
// Best effort: give the SDK its graceful shutdown before the document dies.
|
|
224
|
+
await api.runtime?.sendMessage?.({ type: OFFSCREEN_DISABLE_MESSAGE });
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
/* the document may already be gone, or have no listener */
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
await api.offscreen.closeDocument();
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
// closeDocument rejects when there is no document; either way we are done.
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Serialises applies. A single opt-out arrives twice — once inline from the
|
|
238
|
+
* message handler (so the response reflects reality) and once from
|
|
239
|
+
* `storage.onChanged` — and without this both would read "document exists"
|
|
240
|
+
* before either closed it, double-calling `closeDocument`. Queueing also covers
|
|
241
|
+
* a user toggling faster than a create/close round-trip.
|
|
242
|
+
*/
|
|
243
|
+
let applyQueue = Promise.resolve();
|
|
244
|
+
const doApplyZeroGpuConsent = async (consent, options) => {
|
|
245
|
+
if (consent.optedIn) {
|
|
246
|
+
await ensureZeroGpuOffscreen(options);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
await stopZeroGpuOffscreen(options);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
/** Start or stop to match the stored decision. Safe to call repeatedly. */
|
|
253
|
+
const applyZeroGpuConsent = (consent, options = {}) => {
|
|
254
|
+
// A failed apply must not poison the queue for every later call.
|
|
255
|
+
applyQueue = applyQueue.then(() => doApplyZeroGpuConsent(consent, options), () => doApplyZeroGpuConsent(consent, options));
|
|
256
|
+
return applyQueue;
|
|
257
|
+
};
|
|
258
|
+
/** Start only if the user is opted in — for `onInstalled` / `onStartup`. */
|
|
259
|
+
const startZeroGpuIfConsented = async (options = {}) => {
|
|
260
|
+
await applyZeroGpuConsent(await getZeroGpuConsent(), options);
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Handle one message. `source` records who asked, so a flip that came from the
|
|
264
|
+
* hosted page is distinguishable from one made inside the extension.
|
|
265
|
+
*/
|
|
266
|
+
const handleMessage = async (message, source, options) => {
|
|
267
|
+
switch (message.type) {
|
|
268
|
+
case ZEROGPU_BRIDGE_MESSAGES.ping:
|
|
269
|
+
// Lets the settings page tell "extension not installed" apart from
|
|
270
|
+
// "installed and opted out".
|
|
271
|
+
return { ok: true, installed: true, extensionId: getChrome()?.runtime?.id };
|
|
272
|
+
case ZEROGPU_BRIDGE_MESSAGES.getConsent:
|
|
273
|
+
return { ok: true, consent: await getZeroGpuConsent() };
|
|
274
|
+
case ZEROGPU_BRIDGE_MESSAGES.setConsent: {
|
|
275
|
+
if (typeof message.optedIn !== 'boolean') {
|
|
276
|
+
return { ok: false, error: 'optedIn must be a boolean' };
|
|
277
|
+
}
|
|
278
|
+
const consent = await setZeroGpuConsent(message.optedIn, source);
|
|
279
|
+
// storage.onChanged also fires, but applying here means the caller's
|
|
280
|
+
// response already reflects the real state.
|
|
281
|
+
await applyZeroGpuConsent(consent, options);
|
|
282
|
+
return { ok: true, consent };
|
|
283
|
+
}
|
|
284
|
+
default:
|
|
285
|
+
return { ok: false, error: 'unsupported message' };
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Install the bridge. Call once from the service worker:
|
|
290
|
+
*
|
|
291
|
+
* ZeroGpuBackground.registerZeroGpuConsentBridge();
|
|
292
|
+
*
|
|
293
|
+
* Wires up: external messages from the allowlisted settings page, internal
|
|
294
|
+
* messages from the extension's own popup/options, storage changes from any
|
|
295
|
+
* context, and the install/startup gate.
|
|
296
|
+
*/
|
|
297
|
+
const registerZeroGpuConsentBridge = (options = {}) => {
|
|
298
|
+
const api = getChrome();
|
|
299
|
+
const runtime = api?.runtime;
|
|
300
|
+
if (!runtime)
|
|
301
|
+
return;
|
|
302
|
+
const allowedOrigins = options.allowedOrigins ?? DEFAULT_ALLOWED_ORIGINS;
|
|
303
|
+
// --- the hosted settings page -------------------------------------------
|
|
304
|
+
runtime.onMessageExternal?.addListener((rawMessage, sender, sendResponse) => {
|
|
305
|
+
// Origin check FIRST, before the message is even inspected. Strict equality:
|
|
306
|
+
// a suffix or `includes` test would accept https://zerogpu.ai.attacker.com.
|
|
307
|
+
if (!sender?.origin || !allowedOrigins.includes(sender.origin)) {
|
|
308
|
+
sendResponse({ ok: false, error: 'origin not allowed' });
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (!rawMessage || typeof rawMessage !== 'object') {
|
|
312
|
+
sendResponse({ ok: false, error: 'bad message' });
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
void handleMessage(rawMessage, 'settings-page', options)
|
|
316
|
+
.then(sendResponse)
|
|
317
|
+
.catch((error) => sendResponse({ ok: false, error: error instanceof Error ? error.message : String(error) }));
|
|
318
|
+
return true; // response is async
|
|
319
|
+
});
|
|
320
|
+
// --- the extension's own popup / options page ----------------------------
|
|
321
|
+
runtime.onMessage?.addListener((rawMessage, _sender, sendResponse) => {
|
|
322
|
+
if (!rawMessage || typeof rawMessage !== 'object')
|
|
323
|
+
return;
|
|
324
|
+
const message = rawMessage;
|
|
325
|
+
// Leave every other message (including the offscreen protocol) alone.
|
|
326
|
+
if (!Object.values(ZEROGPU_BRIDGE_MESSAGES).includes(message.type))
|
|
327
|
+
return;
|
|
328
|
+
void handleMessage(message, 'extension', options)
|
|
329
|
+
.then(sendResponse)
|
|
330
|
+
.catch((error) => sendResponse({ ok: false, error: error instanceof Error ? error.message : String(error) }));
|
|
331
|
+
return true;
|
|
332
|
+
});
|
|
333
|
+
// --- any other writer (another window, a direct storage write) -----------
|
|
334
|
+
onZeroGpuConsentChanged((consent) => {
|
|
335
|
+
void applyZeroGpuConsent(consent, options);
|
|
336
|
+
});
|
|
337
|
+
// --- install / browser startup ------------------------------------------
|
|
338
|
+
runtime.onInstalled?.addListener(() => {
|
|
339
|
+
void startZeroGpuIfConsented(options);
|
|
340
|
+
});
|
|
341
|
+
runtime.onStartup?.addListener(() => {
|
|
342
|
+
void startZeroGpuIfConsented(options);
|
|
343
|
+
});
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
exports.DEFAULT_ALLOWED_ORIGINS = DEFAULT_ALLOWED_ORIGINS;
|
|
347
|
+
exports.DEFAULT_CONSENT = DEFAULT_CONSENT;
|
|
348
|
+
exports.ZEROGPU_BRIDGE_MESSAGES = ZEROGPU_BRIDGE_MESSAGES;
|
|
349
|
+
exports.ZEROGPU_CONSENT_KEY = ZEROGPU_CONSENT_KEY;
|
|
350
|
+
exports.ZEROGPU_SETTINGS_BASE_URL = ZEROGPU_SETTINGS_BASE_URL;
|
|
351
|
+
exports.applyZeroGpuConsent = applyZeroGpuConsent;
|
|
352
|
+
exports.buildZeroGpuSettingsUrl = buildZeroGpuSettingsUrl;
|
|
353
|
+
exports.ensureZeroGpuOffscreen = ensureZeroGpuOffscreen;
|
|
354
|
+
exports.getZeroGpuConsent = getZeroGpuConsent;
|
|
355
|
+
exports.isZeroGpuOptedIn = isZeroGpuOptedIn;
|
|
356
|
+
exports.onZeroGpuConsentChanged = onZeroGpuConsentChanged;
|
|
357
|
+
exports.registerZeroGpuConsentBridge = registerZeroGpuConsentBridge;
|
|
358
|
+
exports.setZeroGpuConsent = setZeroGpuConsent;
|
|
359
|
+
exports.startZeroGpuIfConsented = startZeroGpuIfConsented;
|
|
360
|
+
exports.stopZeroGpuOffscreen = stopZeroGpuOffscreen;
|
|
361
|
+
|
|
362
|
+
return exports;
|
|
363
|
+
|
|
364
|
+
})({});
|
|
365
|
+
//# sourceMappingURL=zerogpu-background.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zerogpu-background.js","sources":["../../../src/extension/consent.ts","../../../src/extension/background.ts"],"sourcesContent":[null,null],"names":[],"mappings":";;;IAAA;;;;;;;;;;;IAWG;IAEH;AACO,UAAM,mBAAmB,GAAG;IAYnC;;;;IAIG;AACI,UAAM,eAAe,GAAmB;I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