@zerogpu/browser-extension-sdk 0.2.1-dev.202608131557.g7df119f → 0.2.2-dev.202608191151.g3b3d3f1
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/dist/assets/zerogpu-assets.json +2 -2
- package/dist/extension/zerogpu-offscreen.js +103 -11
- package/dist/extension/zerogpu-offscreen.js.map +1 -1
- package/dist/manifest.json +5 -5
- package/dist/types/runtime/tracking-script.d.ts +9 -5
- package/dist/v/{zerogpu-browser-sdk.644d5261aa70.umd.js → zerogpu-browser-sdk.5722c6f5ff1a.umd.js} +104 -12
- package/dist/v/{zerogpu-browser-sdk.644d5261aa70.umd.js.map → zerogpu-browser-sdk.5722c6f5ff1a.umd.js.map} +1 -1
- package/dist/zerogpu-browser-sdk.cjs +103 -11
- package/dist/zerogpu-browser-sdk.cjs.map +1 -1
- package/dist/zerogpu-browser-sdk.esm.js +103 -11
- package/dist/zerogpu-browser-sdk.esm.js.map +1 -1
- package/dist/zerogpu-browser-sdk.umd.js +103 -11
- package/dist/zerogpu-browser-sdk.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"sdkVersion": "0.2.
|
|
2
|
+
"sdkVersion": "0.2.2-dev.202608191151.g3b3d3f1+3b3d3f1",
|
|
3
3
|
"channel": "development",
|
|
4
4
|
"transformersVersion": "2.17.2",
|
|
5
5
|
"wllamaVersion": "2.3.5",
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
"wllama/single-thread/wllama.wasm",
|
|
15
15
|
"wllama/multi-thread/wllama.wasm"
|
|
16
16
|
],
|
|
17
|
-
"builtAt": "2026-08-
|
|
17
|
+
"builtAt": "2026-08-19T11:51:49.937Z"
|
|
18
18
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const SDK_VERSION = typeof "0.2.
|
|
2
|
-
? "0.2.
|
|
1
|
+
const SDK_VERSION = typeof "0.2.2-dev.202608191151.g3b3d3f1+3b3d3f1" === 'string' && "0.2.2-dev.202608191151.g3b3d3f1+3b3d3f1".length > 0
|
|
2
|
+
? "0.2.2-dev.202608191151.g3b3d3f1+3b3d3f1"
|
|
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
|
|
@@ -1919,9 +1919,12 @@ const fireTrackingPixel = (url, timeoutMs = DEFAULT_TIMEOUT_MS) => {
|
|
|
1919
1919
|
*
|
|
1920
1920
|
* Progressive:
|
|
1921
1921
|
* 1. If a runner URL is configured, run the tag in the framed runner.
|
|
1922
|
-
* 2. Otherwise
|
|
1923
|
-
*
|
|
1924
|
-
*
|
|
1922
|
+
* 2. Otherwise, on an ordinary web page or WebView (including a Telegram Mini
|
|
1923
|
+
* App) with no restrictive `script-src` CSP, inject a real `<script>`
|
|
1924
|
+
* element so the tag executes directly in the page.
|
|
1925
|
+
* 3. Failing both (no DOM, or a CSP that blocks the injected script), fall back
|
|
1926
|
+
* to a credentialed request beacon so the impression at least reaches the ad
|
|
1927
|
+
* server with the user's real IP/UA/cookies (the tag's JS does not run).
|
|
1925
1928
|
*
|
|
1926
1929
|
* Never rejects: a tag is best-effort and must not affect inference.
|
|
1927
1930
|
*/
|
|
@@ -2068,18 +2071,107 @@ const fireBeacon = (url, timeoutMs) => {
|
|
|
2068
2071
|
});
|
|
2069
2072
|
};
|
|
2070
2073
|
/**
|
|
2071
|
-
*
|
|
2072
|
-
*
|
|
2074
|
+
* Execute the tag by injecting a real `<script>` element into the host document.
|
|
2075
|
+
*
|
|
2076
|
+
* This is how a JS tag is *meant* to run on an ordinary web page — including a
|
|
2077
|
+
* Telegram Mini App or any other WebView, which is just a normal DOM with no
|
|
2078
|
+
* extension-style `script-src 'self'` lockdown. The browser fetches the tag with
|
|
2079
|
+
* `Sec-Fetch-Dest: script` and runs it in the page, so the tag's own logic
|
|
2080
|
+
* (impression beacons, etc.) actually executes.
|
|
2081
|
+
*
|
|
2082
|
+
* Unlike a pixel, `load` means the code ran and `error` means it did not: a CSP
|
|
2083
|
+
* `script-src` that forbids the origin (e.g. the MV3 extension's offscreen
|
|
2084
|
+
* document) blocks the load. On error we resolve `null` so the caller can fall
|
|
2085
|
+
* back to the beacon; on load we resolve 'fired' and do NOT beacon, so an
|
|
2086
|
+
* executed tag is never counted twice.
|
|
2087
|
+
*
|
|
2088
|
+
* Resolves:
|
|
2089
|
+
* - 'fired' the script loaded and executed
|
|
2090
|
+
* - 'timeout' it neither loaded nor errored in time (genuinely unknown)
|
|
2091
|
+
* - null no DOM, or the injection failed/was blocked → try the beacon
|
|
2092
|
+
*
|
|
2093
|
+
* Never rejects.
|
|
2094
|
+
*/
|
|
2095
|
+
// Only https tags are ever executed in-page. Tier 2 runs the tag in the host
|
|
2096
|
+
// document's context (full DOM / same-origin storage / cookies), so a non-https
|
|
2097
|
+
// URL — http:, data:, blob:, javascript: — must never reach `script.src`. Such
|
|
2098
|
+
// tags resolve `null` here and fall through to the beacon, which still delivers
|
|
2099
|
+
// the impression without running any code.
|
|
2100
|
+
const isExecutableTagUrl = (url) => {
|
|
2101
|
+
try {
|
|
2102
|
+
return new URL(url).protocol === 'https:';
|
|
2103
|
+
}
|
|
2104
|
+
catch {
|
|
2105
|
+
return false;
|
|
2106
|
+
}
|
|
2107
|
+
};
|
|
2108
|
+
const fireViaScriptTag = (url, timeoutMs) => {
|
|
2109
|
+
if (typeof document === 'undefined' || !isExecutableTagUrl(url)) {
|
|
2110
|
+
return Promise.resolve(null);
|
|
2111
|
+
}
|
|
2112
|
+
return new Promise((resolve) => {
|
|
2113
|
+
let settled = false;
|
|
2114
|
+
let script;
|
|
2115
|
+
let timer;
|
|
2116
|
+
const settle = (status) => {
|
|
2117
|
+
if (settled)
|
|
2118
|
+
return;
|
|
2119
|
+
settled = true;
|
|
2120
|
+
if (timer !== undefined)
|
|
2121
|
+
clearTimeout(timer);
|
|
2122
|
+
if (script) {
|
|
2123
|
+
script.onload = null;
|
|
2124
|
+
script.onerror = null;
|
|
2125
|
+
script.remove();
|
|
2126
|
+
}
|
|
2127
|
+
resolve(status);
|
|
2128
|
+
};
|
|
2129
|
+
try {
|
|
2130
|
+
timer = setTimeout(() => settle('timeout'), timeoutMs);
|
|
2131
|
+
script = document.createElement('script');
|
|
2132
|
+
script.async = true;
|
|
2133
|
+
// A tag's JS runs synchronously as it loads, so `onload` fires *after* it
|
|
2134
|
+
// has executed. `error` — a network failure or a CSP `script-src` block —
|
|
2135
|
+
// means it did not run: resolve null and let the caller beacon instead.
|
|
2136
|
+
script.onload = () => settle('fired');
|
|
2137
|
+
script.onerror = () => settle(null);
|
|
2138
|
+
script.src = url;
|
|
2139
|
+
(document.head ?? document.documentElement).appendChild(script);
|
|
2140
|
+
}
|
|
2141
|
+
catch {
|
|
2142
|
+
settle(null);
|
|
2143
|
+
}
|
|
2144
|
+
});
|
|
2145
|
+
};
|
|
2146
|
+
/**
|
|
2147
|
+
* Fire a JavaScript tracking tag. Executes it wherever it can — the framed
|
|
2148
|
+
* runner, or an injected `<script>` on a normal page/WebView — and only falls
|
|
2149
|
+
* back to a non-executing beacon when neither can run it. Never rejects.
|
|
2073
2150
|
*/
|
|
2074
2151
|
const fireTrackingScript = async (url, timeoutMs = DEFAULT_TIMEOUT_MS) => {
|
|
2152
|
+
// 1. Framed runner: executes off the extension origin when a runner is
|
|
2153
|
+
// configured (the MV3 extension path).
|
|
2075
2154
|
try {
|
|
2076
2155
|
const win = await ensureRunner();
|
|
2077
|
-
if (win)
|
|
2078
|
-
|
|
2156
|
+
if (win) {
|
|
2157
|
+
// 'skipped' means the runner could not execute the tag, so it did not
|
|
2158
|
+
// run — fall through to the remaining tiers. 'fired'/'timeout' are terminal.
|
|
2159
|
+
const outcome = await runInRunner(win, url, timeoutMs);
|
|
2160
|
+
if (outcome !== 'skipped')
|
|
2161
|
+
return outcome;
|
|
2162
|
+
}
|
|
2079
2163
|
}
|
|
2080
2164
|
catch {
|
|
2081
|
-
// Fall through
|
|
2082
|
-
}
|
|
2165
|
+
// Fall through on any runner failure.
|
|
2166
|
+
}
|
|
2167
|
+
// 2. Inject a real <script> so the tag executes in the page. This is the
|
|
2168
|
+
// normal path for the SDK loaded on a site via the loader, and for a
|
|
2169
|
+
// Telegram Mini App / other WebViews.
|
|
2170
|
+
const executed = await fireViaScriptTag(url, timeoutMs);
|
|
2171
|
+
if (executed !== null)
|
|
2172
|
+
return executed;
|
|
2173
|
+
// 3. Last resort: fire the request without executing it, so the impression
|
|
2174
|
+
// still reaches the ad server with the user's real IP/UA/cookies.
|
|
2083
2175
|
return fireBeacon(url, timeoutMs);
|
|
2084
2176
|
};
|
|
2085
2177
|
|