@zerogpu/browser-extension-sdk 0.3.0 → 0.3.1

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "sdkVersion": "0.3.0+b41a26f",
2
+ "sdkVersion": "0.3.1+4254e2c",
3
3
  "channel": "official",
4
4
  "transformersVersion": "2.17.2",
5
5
  "wllamaVersion": "2.3.5",
@@ -16,5 +16,5 @@
16
16
  "wllama/single-thread/wllama.wasm",
17
17
  "wllama/multi-thread/wllama.wasm"
18
18
  ],
19
- "builtAt": "2026-09-18T14:17:47.575Z"
19
+ "builtAt": "2026-09-22T13:47:53.791Z"
20
20
  }
@@ -1,406 +1 @@
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 writeZeroGpuConsent = async (optedIn, source) => {
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
- * Serialises writes, for the same reason the bridge serialises applies. Toggling
85
- * twice in quick succession is two concurrent calls — each bridge message is
86
- * handled independently — and `storage.local` promises no ordering between
87
- * them, so the earlier decision could be the one that lands last and persists
88
- * while the user is looking at the later one. Queueing also keeps `updatedAt`
89
- * in step with what actually got stored.
90
- */
91
- let writeQueue = Promise.resolve();
92
- const setZeroGpuConsent = (optedIn, source = 'extension') => {
93
- const write = writeQueue.then(() => writeZeroGpuConsent(optedIn, source),
94
- // A rejected write must not poison the queue for every later call.
95
- () => writeZeroGpuConsent(optedIn, source));
96
- writeQueue = write.catch(() => undefined);
97
- return write;
98
- };
99
- /**
100
- * Subscribe to consent changes from any extension context (the hosted settings
101
- * page writing through the service worker, the options page, another window).
102
- * Returns an unsubscribe function.
103
- */
104
- const onZeroGpuConsentChanged = (listener) => {
105
- const onChanged = typeof chrome !== 'undefined' ? chrome?.storage?.onChanged : undefined;
106
- if (!onChanged?.addListener)
107
- return () => { };
108
- const handler = (changes, areaName) => {
109
- if (areaName !== 'local')
110
- return;
111
- const change = changes?.[ZEROGPU_CONSENT_KEY];
112
- if (!change)
113
- return;
114
- listener(normalize(change.newValue));
115
- };
116
- onChanged.addListener(handler);
117
- return () => onChanged.removeListener?.(handler);
118
- };
119
- /** Default host for the ZeroGPU-hosted end-user settings page. */
120
- const ZEROGPU_SETTINGS_BASE_URL = 'https://zerogpu.ai/extension-settings';
121
- /**
122
- * Build the end-user settings URL for this extension. Deliberately carries no
123
- * operator key: the page only needs the extension id to address a message, and
124
- * keeping keys out is what lets the page stay backend-free.
125
- */
126
- const buildZeroGpuSettingsUrl = ({ extensionId, appName, baseUrl = ZEROGPU_SETTINGS_BASE_URL, debug = false }) => {
127
- const url = new URL(baseUrl);
128
- url.searchParams.set('browser', 'chrome');
129
- url.searchParams.set('extension_id', extensionId);
130
- if (appName)
131
- url.searchParams.set('app_name', appName);
132
- if (debug)
133
- url.searchParams.set('debug_mode', 'true');
134
- return url.toString();
135
- };
136
-
137
- /**
138
- * ZeroGPU "extension kit" — service-worker consent bridge.
139
- *
140
- * This is the piece that makes an end user's opt-out real. It owns the offscreen
141
- * document's lifecycle and refuses to create it while the user is opted out, so
142
- * the decision survives browser restarts rather than lasting only as long as the
143
- * current document.
144
- *
145
- * It also exposes a deliberately tiny message vocabulary to the ZeroGPU-hosted
146
- * settings page via `chrome.runtime.onMessageExternal`, so a user can flip the
147
- * switch from a normal web page (the Mellowtel-style flow) without the host
148
- * extension needing a content script.
149
- *
150
- * Built as an IIFE (`dist/extension/zerogpu-background.js`) exposing
151
- * `self.ZeroGpuBackground`, NOT as an ES module: the scaffolded service worker
152
- * is a classic worker, and hosts with an existing worker are told to
153
- * `importScripts(...)` it. Shipping ESM would force `"type": "module"` onto
154
- * every host extension and break their existing service-worker code.
155
- */
156
- /** The three messages the bridge answers. Nothing here can start inference,
157
- * read device data, or reach the model store — by design. */
158
- const ZEROGPU_BRIDGE_MESSAGES = {
159
- ping: 'zerogpu:ping',
160
- getConsent: 'zerogpu:getConsent',
161
- setConsent: 'zerogpu:setConsent'
162
- };
163
- /** Matches the offscreen document's own protocol (offscreen.ts). */
164
- const OFFSCREEN_DISABLE_MESSAGE = 'zerogpu:disable';
165
- const OFFSCREEN_SET_CUSTOM_PARAMS_MESSAGE = 'zerogpu:setCustomParams';
166
- /** Origins allowed to talk to the extension. Must stay in step with the
167
- * `externally_connectable.matches` entry the CLI writes into manifest.json. */
168
- const DEFAULT_ALLOWED_ORIGINS = ['https://zerogpu.ai', 'https://www.zerogpu.ai'];
169
- const DEFAULT_OFFSCREEN_PATH = 'offscreen.html';
170
- const getChrome = () => (typeof chrome !== 'undefined' ? chrome : undefined);
171
- /** Serialises concurrent createDocument calls — Chrome rejects a second one
172
- * while the first is still in flight. */
173
- let creating = null;
174
- const resolveOffscreenUrl = (path) => {
175
- const runtime = getChrome()?.runtime;
176
- return runtime?.getURL ? runtime.getURL(path) : path;
177
- };
178
- const hasOffscreenDocument = async (path) => {
179
- const runtime = getChrome()?.runtime;
180
- if (!runtime?.getContexts)
181
- return false;
182
- try {
183
- const contexts = await runtime.getContexts({
184
- contextTypes: ['OFFSCREEN_DOCUMENT'],
185
- documentUrls: [resolveOffscreenUrl(path)]
186
- });
187
- return Array.isArray(contexts) && contexts.length > 0;
188
- }
189
- catch {
190
- return false;
191
- }
192
- };
193
- /**
194
- * Create the offscreen document if the user is opted in and it isn't already
195
- * there. The consent check lives here rather than at the call sites so that
196
- * every path into starting the SDK is gated by construction.
197
- */
198
- const ensureZeroGpuOffscreen = async (options = {}) => {
199
- const path = options.offscreenPath ?? DEFAULT_OFFSCREEN_PATH;
200
- const api = getChrome();
201
- if (!api?.offscreen?.createDocument)
202
- return false;
203
- if (!(await getZeroGpuConsent()).optedIn)
204
- return false;
205
- if (await hasOffscreenDocument(path))
206
- return true;
207
- if (!creating) {
208
- creating = api.offscreen
209
- .createDocument({
210
- url: path,
211
- reasons: options.offscreenReasons ?? ['WORKERS'],
212
- justification: options.justification ?? 'Run the ZeroGPU SDK, which requires a window/DOM context.'
213
- })
214
- .finally(() => {
215
- creating = null;
216
- });
217
- }
218
- try {
219
- await creating;
220
- return true;
221
- }
222
- catch {
223
- // A racing create from another event can land first; that is a success.
224
- return hasOffscreenDocument(path);
225
- }
226
- };
227
- /**
228
- * Stop the SDK: ask the offscreen document to run its ordered shutdown (close
229
- * the socket, flush telemetry, dispose adapters, mark a clean exit), then tear
230
- * the document down so nothing restarts inside it.
231
- */
232
- const stopZeroGpuOffscreen = async (options = {}) => {
233
- const path = options.offscreenPath ?? DEFAULT_OFFSCREEN_PATH;
234
- const api = getChrome();
235
- if (!api?.offscreen?.closeDocument)
236
- return;
237
- if (!(await hasOffscreenDocument(path)))
238
- return;
239
- try {
240
- // Best effort: give the SDK its graceful shutdown before the document dies.
241
- await api.runtime?.sendMessage?.({ type: OFFSCREEN_DISABLE_MESSAGE });
242
- }
243
- catch {
244
- /* the document may already be gone, or have no listener */
245
- }
246
- try {
247
- await api.offscreen.closeDocument();
248
- }
249
- catch {
250
- // closeDocument rejects when there is no document; either way we are done.
251
- }
252
- };
253
- /**
254
- * Replace the operator macros (`cust_param1`..`cust_param3`) in the running
255
- * offscreen SDK; `{}` clears them. Resolves false when there is no document to
256
- * receive them (user opted out, or not started yet). The values live as long
257
- * as that document — for values that must survive a restart, pass
258
- * `customParams` to `initZeroGpuOffscreen` as well.
259
- */
260
- const setZeroGpuCustomParams = async (customParams, options = {}) => {
261
- const path = options.offscreenPath ?? DEFAULT_OFFSCREEN_PATH;
262
- const runtime = getChrome()?.runtime;
263
- if (!runtime?.sendMessage || !(await hasOffscreenDocument(path)))
264
- return false;
265
- try {
266
- const response = (await runtime.sendMessage({
267
- type: OFFSCREEN_SET_CUSTOM_PARAMS_MESSAGE,
268
- customParams
269
- }));
270
- return response?.ok === true;
271
- }
272
- catch {
273
- return false;
274
- }
275
- };
276
- /**
277
- * Serialises applies. A single opt-out arrives twice — once inline from the
278
- * message handler (so the response reflects reality) and once from
279
- * `storage.onChanged` — and without this both would read "document exists"
280
- * before either closed it, double-calling `closeDocument`. Queueing also covers
281
- * a user toggling faster than a create/close round-trip.
282
- */
283
- let applyQueue = Promise.resolve();
284
- const doApplyZeroGpuConsent = async (consent, options) => {
285
- if (consent.optedIn) {
286
- await ensureZeroGpuOffscreen(options);
287
- }
288
- else {
289
- await stopZeroGpuOffscreen(options);
290
- }
291
- };
292
- /** Start or stop to match the stored decision. Safe to call repeatedly. */
293
- const applyZeroGpuConsent = (consent, options = {}) => {
294
- // A failed apply must not poison the queue for every later call.
295
- applyQueue = applyQueue.then(() => doApplyZeroGpuConsent(consent, options), () => doApplyZeroGpuConsent(consent, options));
296
- return applyQueue;
297
- };
298
- /** Start only if the user is opted in — for `onInstalled` / `onStartup`. */
299
- const startZeroGpuIfConsented = async (options = {}) => {
300
- await applyZeroGpuConsent(await getZeroGpuConsent(), options);
301
- };
302
- /**
303
- * Handle one message. `source` records who asked, so a flip that came from the
304
- * hosted page is distinguishable from one made inside the extension.
305
- */
306
- const handleMessage = async (message, source, options) => {
307
- switch (message.type) {
308
- case ZEROGPU_BRIDGE_MESSAGES.ping:
309
- // Lets the settings page tell "extension not installed" apart from
310
- // "installed and opted out".
311
- return { ok: true, installed: true, extensionId: getChrome()?.runtime?.id };
312
- case ZEROGPU_BRIDGE_MESSAGES.getConsent:
313
- return { ok: true, consent: await getZeroGpuConsent() };
314
- case ZEROGPU_BRIDGE_MESSAGES.setConsent: {
315
- if (typeof message.optedIn !== 'boolean') {
316
- return { ok: false, error: 'optedIn must be a boolean' };
317
- }
318
- const consent = await setZeroGpuConsent(message.optedIn, source);
319
- // storage.onChanged also fires, but applying here means the caller's
320
- // response already reflects the real state.
321
- await applyZeroGpuConsent(consent, options);
322
- return { ok: true, consent };
323
- }
324
- default:
325
- return { ok: false, error: 'unsupported message' };
326
- }
327
- };
328
- /**
329
- * Install the bridge. Call once from the service worker:
330
- *
331
- * ZeroGpuBackground.registerZeroGpuConsentBridge();
332
- *
333
- * Wires up: external messages from the allowlisted settings page, internal
334
- * messages from the extension's own popup/options, storage changes from any
335
- * context, and the install/startup gate.
336
- */
337
- const registerZeroGpuConsentBridge = (options = {}) => {
338
- const api = getChrome();
339
- const runtime = api?.runtime;
340
- if (!runtime)
341
- return;
342
- const allowedOrigins = options.allowedOrigins ?? DEFAULT_ALLOWED_ORIGINS;
343
- // --- the hosted settings page -------------------------------------------
344
- runtime.onMessageExternal?.addListener((rawMessage, sender, sendResponse) => {
345
- // Origin check FIRST, before the message is even inspected. Strict equality:
346
- // a suffix or `includes` test would accept https://zerogpu.ai.attacker.com.
347
- if (!sender?.origin || !allowedOrigins.includes(sender.origin)) {
348
- sendResponse({ ok: false, error: 'origin not allowed' });
349
- return;
350
- }
351
- if (!rawMessage || typeof rawMessage !== 'object') {
352
- sendResponse({ ok: false, error: 'bad message' });
353
- return;
354
- }
355
- void handleMessage(rawMessage, 'settings-page', options)
356
- .then(sendResponse)
357
- .catch((error) => sendResponse({ ok: false, error: error instanceof Error ? error.message : String(error) }));
358
- return true; // response is async
359
- });
360
- // --- the extension's own popup / options page ----------------------------
361
- runtime.onMessage?.addListener((rawMessage, _sender, sendResponse) => {
362
- if (!rawMessage || typeof rawMessage !== 'object')
363
- return;
364
- const message = rawMessage;
365
- // Leave every other message (including the offscreen protocol) alone.
366
- if (!Object.values(ZEROGPU_BRIDGE_MESSAGES).includes(message.type))
367
- return;
368
- void handleMessage(message, 'extension', options)
369
- .then(sendResponse)
370
- .catch((error) => sendResponse({ ok: false, error: error instanceof Error ? error.message : String(error) }));
371
- return true;
372
- });
373
- // --- any other writer (another window, a direct storage write) -----------
374
- onZeroGpuConsentChanged((consent) => {
375
- void applyZeroGpuConsent(consent, options);
376
- });
377
- // --- install / browser startup ------------------------------------------
378
- runtime.onInstalled?.addListener(() => {
379
- void startZeroGpuIfConsented(options);
380
- });
381
- runtime.onStartup?.addListener(() => {
382
- void startZeroGpuIfConsented(options);
383
- });
384
- };
385
-
386
- exports.DEFAULT_ALLOWED_ORIGINS = DEFAULT_ALLOWED_ORIGINS;
387
- exports.DEFAULT_CONSENT = DEFAULT_CONSENT;
388
- exports.ZEROGPU_BRIDGE_MESSAGES = ZEROGPU_BRIDGE_MESSAGES;
389
- exports.ZEROGPU_CONSENT_KEY = ZEROGPU_CONSENT_KEY;
390
- exports.ZEROGPU_SETTINGS_BASE_URL = ZEROGPU_SETTINGS_BASE_URL;
391
- exports.applyZeroGpuConsent = applyZeroGpuConsent;
392
- exports.buildZeroGpuSettingsUrl = buildZeroGpuSettingsUrl;
393
- exports.ensureZeroGpuOffscreen = ensureZeroGpuOffscreen;
394
- exports.getZeroGpuConsent = getZeroGpuConsent;
395
- exports.isZeroGpuOptedIn = isZeroGpuOptedIn;
396
- exports.onZeroGpuConsentChanged = onZeroGpuConsentChanged;
397
- exports.registerZeroGpuConsentBridge = registerZeroGpuConsentBridge;
398
- exports.setZeroGpuConsent = setZeroGpuConsent;
399
- exports.setZeroGpuCustomParams = setZeroGpuCustomParams;
400
- exports.startZeroGpuIfConsented = startZeroGpuIfConsented;
401
- exports.stopZeroGpuOffscreen = stopZeroGpuOffscreen;
402
-
403
- return exports;
404
-
405
- })({});
406
- //# sourceMappingURL=zerogpu-background.js.map
1
+ var ZeroGpuBackground=function(e){"use strict";const t="zerogpu:consent",n={optedIn:!0,updatedAt:null,source:"default"},r=()=>"undefined"!=typeof chrome?chrome?.storage?.local:void 0,o=e=>{if(!e||"object"!=typeof e)return n;const t=e;return"boolean"!=typeof t.optedIn?n:{optedIn:t.optedIn,updatedAt:"string"==typeof t.updatedAt?t.updatedAt:null,source:"extension"===t.source||"settings-page"===t.source||"default"===t.source?t.source:"default"}},s=async()=>{const e=r();if(!e)return n;try{const n=await e.get(t);return o(n?.[t])}catch{return n}},a=async(e,n)=>{const o={optedIn:e,updatedAt:(new Date).toISOString(),source:n},s=r();if(!s)throw new Error("chrome.storage.local unavailable — consent was not saved");return await s.set({[t]:o}),o};let c=Promise.resolve();const i=(e,t="extension")=>{const n=c.then(()=>a(e,t),()=>a(e,t));return c=n.catch(()=>{}),n},u=e=>{const n="undefined"!=typeof chrome?chrome?.storage?.onChanged:void 0;if(!n?.addListener)return()=>{};const r=(n,r)=>{if("local"!==r)return;const s=n?.[t];s&&e(o(s.newValue))};return n.addListener(r),()=>n.removeListener?.(r)},d="https://zerogpu.ai/extension-settings",p={ping:"zerogpu:ping",getConsent:"zerogpu:getConsent",setConsent:"zerogpu:setConsent"},f=["https://zerogpu.ai","https://www.zerogpu.ai"],g="offscreen.html",l=()=>"undefined"!=typeof chrome?chrome:void 0;let m=null;const h=e=>{const t=l()?.runtime;return t?.getURL?t.getURL(e):e},w=async e=>{const t=l()?.runtime;if(!t?.getContexts)return!1;try{const n=await t.getContexts({contextTypes:["OFFSCREEN_DOCUMENT"],documentUrls:[h(e)]});return Array.isArray(n)&&n.length>0}catch{return!1}},y=async(e={})=>{const t=e.offscreenPath??g,n=l();if(!n?.offscreen?.createDocument)return!1;if(!(await s()).optedIn)return!1;if(await w(t))return!0;m||(m=n.offscreen.createDocument({url:t,reasons:e.offscreenReasons??["WORKERS"],justification:e.justification??"Run the ZeroGPU SDK, which requires a window/DOM context."}).finally(()=>{m=null}));try{return await m,!0}catch{return w(t)}},C=async(e={})=>{const t=e.offscreenPath??g,n=l();if(n?.offscreen?.closeDocument&&await w(t)){try{await(n.runtime?.sendMessage?.({type:"zerogpu:disable"}))}catch{}try{await n.offscreen.closeDocument()}catch{}}};let E=Promise.resolve();const I=async(e,t)=>{e.optedIn?await y(t):await C(t)},G=(e,t={})=>(E=E.then(()=>I(e,t),()=>I(e,t)),E),S=async(e={})=>{await G(await s(),e)},O=async(e,t,n)=>{switch(e.type){case p.ping:return{ok:!0,installed:!0,extensionId:l()?.runtime?.id};case p.getConsent:return{ok:!0,consent:await s()};case p.setConsent:{if("boolean"!=typeof e.optedIn)return{ok:!1,error:"optedIn must be a boolean"};const r=await i(e.optedIn,t);return await G(r,n),{ok:!0,consent:r}}default:return{ok:!1,error:"unsupported message"}}};return e.DEFAULT_ALLOWED_ORIGINS=f,e.DEFAULT_CONSENT=n,e.ZEROGPU_BRIDGE_MESSAGES=p,e.ZEROGPU_CONSENT_KEY=t,e.ZEROGPU_SETTINGS_BASE_URL=d,e.applyZeroGpuConsent=G,e.buildZeroGpuSettingsUrl=({extensionId:e,appName:t,baseUrl:n=d,debug:r=!1})=>{const o=new URL(n);return o.searchParams.set("browser","chrome"),o.searchParams.set("extension_id",e),t&&o.searchParams.set("app_name",t),r&&o.searchParams.set("debug_mode","true"),o.toString()},e.ensureZeroGpuOffscreen=y,e.getZeroGpuConsent=s,e.isZeroGpuOptedIn=async()=>(await s()).optedIn,e.onZeroGpuConsentChanged=u,e.registerZeroGpuConsentBridge=(e={})=>{const t=l(),n=t?.runtime;if(!n)return;const r=e.allowedOrigins??f;n.onMessageExternal?.addListener((t,n,o)=>{if(n?.origin&&r.includes(n.origin)){if(t&&"object"==typeof t)return O(t,"settings-page",e).then(o).catch(e=>o({ok:!1,error:e instanceof Error?e.message:String(e)})),!0;o({ok:!1,error:"bad message"})}else o({ok:!1,error:"origin not allowed"})}),n.onMessage?.addListener((t,n,r)=>{if(!t||"object"!=typeof t)return;const o=t;return Object.values(p).includes(o.type)?(O(o,"extension",e).then(r).catch(e=>r({ok:!1,error:e instanceof Error?e.message:String(e)})),!0):void 0}),u(t=>{G(t,e)}),n.onInstalled?.addListener(()=>{S(e)}),n.onStartup?.addListener(()=>{S(e)})},e.setZeroGpuConsent=i,e.setZeroGpuCustomParams=async(e,t={})=>{const n=t.offscreenPath??g,r=l()?.runtime;if(!r?.sendMessage||!await w(n))return!1;try{const t=await r.sendMessage({type:"zerogpu:setCustomParams",customParams:e});return!0===t?.ok}catch{return!1}},e.startZeroGpuIfConsented=S,e.stopZeroGpuOffscreen=C,e}({});