@zerogpu/browser-extension-sdk 0.2.3 → 0.2.4
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 +171 -29
- package/dist/assets/zerogpu-assets.json +2 -2
- package/dist/extension/zerogpu-background.js +17 -1
- package/dist/extension/zerogpu-background.js.map +1 -1
- package/dist/extension/zerogpu-offscreen.js +11 -2
- package/dist/extension/zerogpu-offscreen.js.map +1 -1
- package/dist/extension/zerogpu-settings-link.js +9 -0
- package/dist/extension/zerogpu-settings-link.js.map +1 -1
- package/dist/manifest.json +5 -5
- package/dist/types/extension/consent.d.ts +0 -5
- package/dist/v/{zerogpu-browser-sdk.85b3f7e3cc11.umd.js → zerogpu-browser-sdk.a6e1d6604337.umd.js} +3 -3
- package/dist/v/{zerogpu-browser-sdk.85b3f7e3cc11.umd.js.map → zerogpu-browser-sdk.a6e1d6604337.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 +45 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const SDK_VERSION = typeof "0.2.
|
|
4
|
-
? "0.2.
|
|
3
|
+
const SDK_VERSION = typeof "0.2.4+81d7c7a" === 'string' && "0.2.4+81d7c7a".length > 0
|
|
4
|
+
? "0.2.4+81d7c7a"
|
|
5
5
|
: '0.0.0-dev';
|
|
6
6
|
|
|
7
7
|
const ORCHESTRATOR_BASE_URL = typeof "https://devices.zerogpu.ai" === 'string' && "https://devices.zerogpu.ai".length > 0
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const SDK_VERSION = typeof "0.2.
|
|
2
|
-
? "0.2.
|
|
1
|
+
const SDK_VERSION = typeof "0.2.4+81d7c7a" === 'string' && "0.2.4+81d7c7a".length > 0
|
|
2
|
+
? "0.2.4+81d7c7a"
|
|
3
3
|
: '0.0.0-dev';
|
|
4
4
|
|
|
5
5
|
const ORCHESTRATOR_BASE_URL = typeof "https://devices.zerogpu.ai" === 'string' && "https://devices.zerogpu.ai".length > 0
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ZeroGpuBrowserSdk = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
const SDK_VERSION = typeof "0.2.
|
|
8
|
-
? "0.2.
|
|
7
|
+
const SDK_VERSION = typeof "0.2.4+81d7c7a" === 'string' && "0.2.4+81d7c7a".length > 0
|
|
8
|
+
? "0.2.4+81d7c7a"
|
|
9
9
|
: '0.0.0-dev';
|
|
10
10
|
|
|
11
11
|
const ORCHESTRATOR_BASE_URL = typeof "https://devices.zerogpu.ai" === 'string' && "https://devices.zerogpu.ai".length > 0
|
|
@@ -152,9 +152,17 @@ your manifest, which lets that one page — and only that page — send the
|
|
|
152
152
|
extension three messages:
|
|
153
153
|
|
|
154
154
|
```jsonc
|
|
155
|
-
"externally_connectable": { "matches": ["https://*.zerogpu.ai/*"] }
|
|
155
|
+
"externally_connectable": { "matches": ["https://*.zerogpu.ai/*"], "ids": ["*"] }
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
+
The `ids` entry appears only when you had no `externally_connectable` key at all,
|
|
159
|
+
and it changes nothing: Chrome treats a missing key as "every extension may
|
|
160
|
+
connect, no web page may", but once the key exists an unspecified `ids` means
|
|
161
|
+
"no extension may". Writing `["*"]` records the access you already had rather
|
|
162
|
+
than granting new access. Narrow or remove it whenever you like — if you had
|
|
163
|
+
already declared the key yourself, even as `{}`, your `ids` is left exactly as
|
|
164
|
+
it was.
|
|
165
|
+
|
|
158
166
|
No content script and no extra host permission is involved. The bridge accepts
|
|
159
167
|
only `zerogpu:ping`, `zerogpu:getConsent` and `zerogpu:setConsent`, validates the
|
|
160
168
|
sender's origin against an exact allowlist first, and can neither start
|
|
@@ -220,13 +228,39 @@ control in your own UI rather than a link out:
|
|
|
220
228
|
```js
|
|
221
229
|
// current state
|
|
222
230
|
chrome.runtime.sendMessage({ type: "zerogpu:getConsent" }, (res) => {
|
|
231
|
+
if (!res?.ok) return showUnknown(chrome.runtime.lastError?.message || res?.error);
|
|
223
232
|
console.log(res.consent); // { optedIn, updatedAt, source }
|
|
224
233
|
});
|
|
225
234
|
|
|
226
235
|
// turn it off — the SDK stops immediately and stays off across restarts
|
|
227
|
-
chrome.runtime.sendMessage({ type: "zerogpu:setConsent", optedIn: false })
|
|
236
|
+
chrome.runtime.sendMessage({ type: "zerogpu:setConsent", optedIn: false }, (res) => {
|
|
237
|
+
if (res?.ok) return render(res.consent);
|
|
238
|
+
// The write did not happen, so the SDK is still running. Put the control back
|
|
239
|
+
// where it was; leaving it on the rejected choice tells the user their
|
|
240
|
+
// opt-out saved when it did not.
|
|
241
|
+
restoreLastConfirmed(chrome.runtime.lastError?.message || res?.error);
|
|
242
|
+
});
|
|
228
243
|
```
|
|
229
244
|
|
|
245
|
+
Check `res.ok` on both, and **undo the control when a write fails**. A write only
|
|
246
|
+
fails when the choice was not stored — `setZeroGpuConsent` throws rather than
|
|
247
|
+
report success for a decision that would not survive a restart — and a checkbox
|
|
248
|
+
has already flipped by the time your callback runs, so reporting the error
|
|
249
|
+
without reverting still leaves the user looking at an opt-out that never
|
|
250
|
+
happened. Read `chrome.runtime.lastError` inside the callback too: it is the only
|
|
251
|
+
signal when the service worker never answers, and Chrome logs it as unchecked
|
|
252
|
+
otherwise.
|
|
253
|
+
|
|
254
|
+
Responses are independent, so they can arrive out of order — a read is a storage
|
|
255
|
+
lookup while a write also waits for the offscreen document to start or stop, so
|
|
256
|
+
the initial read can land after an opt-out the user has already made. Ignore any
|
|
257
|
+
answer that is not from your newest request.
|
|
258
|
+
|
|
259
|
+
The scaffolded `options.js` is a working implementation of all of this — the
|
|
260
|
+
stale-response guard, the revert, and the unknown state when nothing has been
|
|
261
|
+
confirmed yet. Copy its handling along with its calls rather than just the two
|
|
262
|
+
`sendMessage` lines above.
|
|
263
|
+
|
|
230
264
|
Or directly, inside the service worker:
|
|
231
265
|
|
|
232
266
|
```js
|
|
@@ -290,6 +324,15 @@ forgotten:
|
|
|
290
324
|
{ "scripts": { "prebuild": "zerogpu vendor" } }
|
|
291
325
|
```
|
|
292
326
|
|
|
327
|
+
`vendor` also adds `"externally_connectable": { "matches": ["https://*.zerogpu.ai/*"] }`
|
|
328
|
+
to your `manifest.json` if it is missing, merging alongside any origins you already
|
|
329
|
+
allow — plus `"ids": ["*"]` when it has to create the key, which preserves the
|
|
330
|
+
extension-to-extension access an absent key already gave you. That entry is what
|
|
331
|
+
lets the ZeroGPU settings page reach your extension, so
|
|
332
|
+
without it the opt-out link is a dead end — and `init` only runs once, so an
|
|
333
|
+
extension scaffolded before the opt-out shipped would never gain it otherwise. Once
|
|
334
|
+
present, later builds leave the file untouched.
|
|
335
|
+
|
|
293
336
|
Now every build re-vendors the runtime automatically. Pick whichever update style
|
|
294
337
|
below fits your workflow.
|
|
295
338
|
|
package/package.json
CHANGED