@proxyshard/shardx 0.1.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.
- package/README.md +247 -0
- package/dist/autoResolve.d.ts +10 -0
- package/dist/autoResolve.d.ts.map +1 -0
- package/dist/autoResolve.js +181 -0
- package/dist/autoResolve.js.map +1 -0
- package/dist/browser.d.ts +43 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +172 -0
- package/dist/browser.js.map +1 -0
- package/dist/geo.d.ts +24 -0
- package/dist/geo.d.ts.map +1 -0
- package/dist/geo.js +129 -0
- package/dist/geo.js.map +1 -0
- package/dist/host.d.ts +10 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +142 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +130 -0
- package/dist/index.js.map +1 -0
- package/dist/profile.d.ts +26 -0
- package/dist/profile.d.ts.map +1 -0
- package/dist/profile.js +89 -0
- package/dist/profile.js.map +1 -0
- package/dist/proxy.d.ts +18 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +212 -0
- package/dist/proxy.js.map +1 -0
- package/dist/randomize.d.ts +20 -0
- package/dist/randomize.d.ts.map +1 -0
- package/dist/randomize.js +123 -0
- package/dist/randomize.js.map +1 -0
- package/dist/runtime.d.ts +49 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +266 -0
- package/dist/runtime.js.map +1 -0
- package/dist/screen.d.ts +5 -0
- package/dist/screen.d.ts.map +1 -0
- package/dist/screen.js +82 -0
- package/dist/screen.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,6DAA6D;AAC7D,EAAE;AACF,uEAAuE;AACvE,+CAA+C;AAC/C,wEAAwE;AACxE,4DAA4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AC;IACxC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC7B,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YACvB,IAAI,CAAC;gBACH,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;gBACrE,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;gBACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxB,MAAM,CAAC,GAAG,MAAM,KAAK,CAAC,oBAAoB,IAAI,eAAe,CAAC,CAAC;oBAC/D,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC;wBACT,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,IAAI,EAAuC,CAAC;wBACjE,IAAI,IAAI,CAAC,oBAAoB;4BAAE,OAAO,IAAI,CAAC,oBAAoB,CAAC;oBAClE,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,MAAM,CAAC,CAAC,kBAAkB,CAAC,CAAC;QAChC,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/geo.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ParsedProxy } from "./proxy.js";
|
|
2
|
+
export type GeoProvider = "ip-api.com" | "ipapi.co" | "ipwho.is";
|
|
3
|
+
export interface GeoInfo {
|
|
4
|
+
ip: string;
|
|
5
|
+
country: string;
|
|
6
|
+
/** ISO-3166 alpha-2. */
|
|
7
|
+
countryCode: string;
|
|
8
|
+
region: string;
|
|
9
|
+
city: string;
|
|
10
|
+
isp: string;
|
|
11
|
+
/** IANA. */
|
|
12
|
+
timezone: string;
|
|
13
|
+
latitude: number;
|
|
14
|
+
longitude: number;
|
|
15
|
+
provider: string;
|
|
16
|
+
/** Comma-separated ISO-639-1; only ipapi.co populates it. */
|
|
17
|
+
languages?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Probe the geo `proxy` exits at, or direct geo when `proxy` is null.
|
|
21
|
+
* Throws on network error or provider-level fail (e.g. ip-api.com status=fail).
|
|
22
|
+
*/
|
|
23
|
+
export declare function geoCheckVia(proxy: ParsedProxy | null, provider?: GeoProvider | string): Promise<GeoInfo>;
|
|
24
|
+
//# sourceMappingURL=geo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geo.d.ts","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,UAAU,GAAG,UAAU,CAAC;AAEjE,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,wBAAwB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAoED;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,WAAW,GAAG,IAAI,EACzB,QAAQ,GAAE,WAAW,GAAG,MAAqB,GAC5C,OAAO,CAAC,OAAO,CAAC,CA6ClB"}
|
package/dist/geo.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Live geo lookup for proxies — mirrors `geo_check_via` in
|
|
2
|
+
// `src-tauri/src/proxy.rs`. Supports the same three providers
|
|
3
|
+
// (ip-api.com / ipapi.co / ipwho.is). HTTP/HTTPS proxies use undici's
|
|
4
|
+
// ProxyAgent; SOCKS5 uses socks-proxy-agent (the only well-supported
|
|
5
|
+
// fetch-compatible SOCKS5 dispatcher in Node land).
|
|
6
|
+
import { ProxyAgent, fetch as undiciFetch } from "undici";
|
|
7
|
+
import { SocksProxyAgent } from "socks-proxy-agent";
|
|
8
|
+
import { request as httpRequest } from "node:http";
|
|
9
|
+
import { request as httpsRequest } from "node:https";
|
|
10
|
+
const URLS = {
|
|
11
|
+
"ip-api.com": "http://ip-api.com/json/?fields=status,message,query,country,countryCode,regionName,city,isp,timezone,lat,lon",
|
|
12
|
+
"ipapi.co": "https://ipapi.co/json/",
|
|
13
|
+
"ipwho.is": "https://ipwho.is/",
|
|
14
|
+
};
|
|
15
|
+
function proxyUrl(p, scheme) {
|
|
16
|
+
if (p.username || p.password) {
|
|
17
|
+
const u = encodeURIComponent(p.username ?? "");
|
|
18
|
+
const pw = encodeURIComponent(p.password ?? "");
|
|
19
|
+
return `${scheme}://${u}:${pw}@${p.host}:${p.port}`;
|
|
20
|
+
}
|
|
21
|
+
return `${scheme}://${p.host}:${p.port}`;
|
|
22
|
+
}
|
|
23
|
+
async function fetchJson(url, proxy, timeoutMs) {
|
|
24
|
+
const ctl = new AbortController();
|
|
25
|
+
const timer = setTimeout(() => ctl.abort(), timeoutMs);
|
|
26
|
+
try {
|
|
27
|
+
if (!proxy) {
|
|
28
|
+
const r = await undiciFetch(url, { signal: ctl.signal });
|
|
29
|
+
if (!r.ok)
|
|
30
|
+
throw new Error(`geo HTTP ${r.status}`);
|
|
31
|
+
return await r.json();
|
|
32
|
+
}
|
|
33
|
+
if (proxy.scheme === "socks5") {
|
|
34
|
+
// socks-proxy-agent works with the global fetch on Node 18+
|
|
35
|
+
// by piggy-backing onto http(s).request via dispatcher fallback.
|
|
36
|
+
// We hand-roll a request through http/https so we keep dependency
|
|
37
|
+
// surface small and DNS resolves through the proxy.
|
|
38
|
+
const agent = new SocksProxyAgent(proxyUrl(proxy, "socks5h"));
|
|
39
|
+
return await new Promise((resolve, reject) => {
|
|
40
|
+
const u = new URL(url);
|
|
41
|
+
const reqFn = u.protocol === "https:" ? httpsRequest : httpRequest;
|
|
42
|
+
const req = reqFn({
|
|
43
|
+
host: u.hostname,
|
|
44
|
+
port: u.port || (u.protocol === "https:" ? 443 : 80),
|
|
45
|
+
path: u.pathname + u.search,
|
|
46
|
+
method: "GET",
|
|
47
|
+
agent,
|
|
48
|
+
signal: ctl.signal,
|
|
49
|
+
}, (res) => {
|
|
50
|
+
const chunks = [];
|
|
51
|
+
res.on("data", (c) => chunks.push(c));
|
|
52
|
+
res.on("end", () => {
|
|
53
|
+
if (typeof res.statusCode === "number" && (res.statusCode < 200 || res.statusCode >= 300)) {
|
|
54
|
+
reject(new Error(`geo HTTP ${res.statusCode}`));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
resolve(JSON.parse(Buffer.concat(chunks).toString("utf8")));
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
reject(e);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
req.on("error", reject);
|
|
66
|
+
req.end();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// HTTP / HTTPS proxy via undici dispatcher.
|
|
70
|
+
const dispatcher = new ProxyAgent(proxyUrl(proxy, proxy.scheme));
|
|
71
|
+
const r = await undiciFetch(url, { signal: ctl.signal, dispatcher });
|
|
72
|
+
if (!r.ok)
|
|
73
|
+
throw new Error(`geo HTTP ${r.status}`);
|
|
74
|
+
return await r.json();
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Probe the geo `proxy` exits at, or direct geo when `proxy` is null.
|
|
82
|
+
* Throws on network error or provider-level fail (e.g. ip-api.com status=fail).
|
|
83
|
+
*/
|
|
84
|
+
export async function geoCheckVia(proxy, provider = "ip-api.com") {
|
|
85
|
+
const url = URLS[provider] ?? URLS["ip-api.com"];
|
|
86
|
+
const body = await fetchJson(url, proxy, 8000);
|
|
87
|
+
const s = (k) => (typeof body[k] === "string" ? body[k] : "");
|
|
88
|
+
const f = (k) => {
|
|
89
|
+
const v = body[k];
|
|
90
|
+
const n = typeof v === "number" ? v : Number(v);
|
|
91
|
+
return Number.isFinite(n) ? n : 0;
|
|
92
|
+
};
|
|
93
|
+
if (provider === "ip-api.com") {
|
|
94
|
+
if (s("status") === "fail")
|
|
95
|
+
throw new Error(`ip-api.com: ${s("message") || "unknown error"}`);
|
|
96
|
+
return {
|
|
97
|
+
ip: s("query"), country: s("country"), countryCode: s("countryCode"),
|
|
98
|
+
region: s("regionName"), city: s("city"), isp: s("isp"),
|
|
99
|
+
timezone: s("timezone"), latitude: f("lat"), longitude: f("lon"),
|
|
100
|
+
provider,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (provider === "ipapi.co") {
|
|
104
|
+
return {
|
|
105
|
+
ip: s("ip"), country: s("country_name"), countryCode: s("country_code"),
|
|
106
|
+
region: s("region"), city: s("city"), isp: s("org"),
|
|
107
|
+
timezone: s("timezone"), latitude: f("latitude"), longitude: f("longitude"),
|
|
108
|
+
provider, languages: s("languages"),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (provider === "ipwho.is") {
|
|
112
|
+
const conn = (body["connection"] && typeof body["connection"] === "object") ? body["connection"] : {};
|
|
113
|
+
const tz = (body["timezone"] && typeof body["timezone"] === "object") ? body["timezone"] : {};
|
|
114
|
+
return {
|
|
115
|
+
ip: s("ip"), country: s("country"), countryCode: s("country_code"),
|
|
116
|
+
region: s("region"), city: s("city"),
|
|
117
|
+
isp: (typeof conn.isp === "string" ? conn.isp : "") || "",
|
|
118
|
+
timezone: (typeof tz.id === "string" ? tz.id : "") || "",
|
|
119
|
+
latitude: f("latitude"), longitude: f("longitude"),
|
|
120
|
+
provider,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
ip: s("query"), country: s("country"), countryCode: s("countryCode"),
|
|
125
|
+
region: "", city: "", isp: "", timezone: "",
|
|
126
|
+
latitude: 0, longitude: 0, provider,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=geo.js.map
|
package/dist/geo.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geo.js","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,8DAA8D;AAC9D,sEAAsE;AACtE,qEAAqE;AACrE,oDAAoD;AACpD,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAwB,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC;AAuBrD,MAAM,IAAI,GAA2B;IACnC,YAAY,EAAE,8GAA8G;IAC5H,UAAU,EAAI,wBAAwB;IACtC,UAAU,EAAI,mBAAmB;CAClC,CAAC;AAEF,SAAS,QAAQ,CAAC,CAAc,EAAE,MAAc;IAC9C,IAAI,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC7B,MAAM,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;QAC/C,MAAM,EAAE,GAAG,kBAAkB,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;QAChD,OAAO,GAAG,MAAM,MAAM,CAAC,IAAI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,CAAC,EAAE,QAAQ;KACpC,CAAC;AACJ,CAAC"}
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Logical CPU count (SMT threads). Falls back to 8 if `os.cpus()` is empty. */
|
|
2
|
+
export declare function hostLogicalCores(): number;
|
|
3
|
+
/** Physical RAM in GiB, best-effort per OS. `null` on failure. */
|
|
4
|
+
export declare function hostRamGb(): number | null;
|
|
5
|
+
/** Round host RAM to Chrome's deviceMemory bucket {8,16,32}; null → 16. */
|
|
6
|
+
export declare function hostRamBucketGb(): number;
|
|
7
|
+
export type Size = readonly [width: number, height: number];
|
|
8
|
+
/** Primary monitor (width, height) in CSS pixels, or null on failure. */
|
|
9
|
+
export declare function hostScreenSize(): Size | null;
|
|
10
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAUA,gFAAgF;AAChF,wBAAgB,gBAAgB,IAAI,MAAM,CAOzC;AAED,kEAAkE;AAClE,wBAAgB,SAAS,IAAI,MAAM,GAAG,IAAI,CAkCzC;AAED,2EAA2E;AAC3E,wBAAgB,eAAe,IAAI,MAAM,CAMxC;AAID,MAAM,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAK5D,yEAAyE;AACzE,wBAAgB,cAAc,IAAI,IAAI,GAAG,IAAI,CAU5C"}
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Host machine introspection — logical CPU count, physical RAM and the
|
|
2
|
+
// primary monitor resolution. Mirrors `host_logical_cores`, `host_ram_gb`,
|
|
3
|
+
// `host_ram_bucket_gb` in `src-tauri/src/lib.rs`.
|
|
4
|
+
//
|
|
5
|
+
// All probes are best-effort: a thrown error returns `null` (or the
|
|
6
|
+
// documented fallback) instead of propagating.
|
|
7
|
+
import { cpus, platform as osPlatform } from "node:os";
|
|
8
|
+
import { execFileSync, execSync } from "node:child_process";
|
|
9
|
+
import { readFileSync } from "node:fs";
|
|
10
|
+
/** Logical CPU count (SMT threads). Falls back to 8 if `os.cpus()` is empty. */
|
|
11
|
+
export function hostLogicalCores() {
|
|
12
|
+
try {
|
|
13
|
+
const n = cpus().length;
|
|
14
|
+
return n > 0 ? n : 8;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return 8;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** Physical RAM in GiB, best-effort per OS. `null` on failure. */
|
|
21
|
+
export function hostRamGb() {
|
|
22
|
+
const plat = osPlatform();
|
|
23
|
+
try {
|
|
24
|
+
if (plat === "darwin") {
|
|
25
|
+
const out = execFileSync("sysctl", ["-n", "hw.memsize"], { stdio: ["ignore", "pipe", "ignore"], timeout: 2000 }).toString().trim();
|
|
26
|
+
const bytes = Number(out);
|
|
27
|
+
if (!Number.isFinite(bytes) || bytes <= 0)
|
|
28
|
+
return null;
|
|
29
|
+
return Math.floor(bytes / (1024 ** 3));
|
|
30
|
+
}
|
|
31
|
+
if (plat === "linux") {
|
|
32
|
+
const txt = readFileSync("/proc/meminfo", "utf8");
|
|
33
|
+
for (const line of txt.split("\n")) {
|
|
34
|
+
if (line.startsWith("MemTotal:")) {
|
|
35
|
+
const kb = Number(line.split(/\s+/)[1]);
|
|
36
|
+
if (!Number.isFinite(kb) || kb <= 0)
|
|
37
|
+
return null;
|
|
38
|
+
return Math.floor(kb / (1024 * 1024));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (plat === "win32") {
|
|
44
|
+
const out = execSync('powershell -NoProfile -Command "(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory"', { stdio: ["ignore", "pipe", "ignore"], timeout: 4000 }).toString().trim();
|
|
45
|
+
const bytes = Number(out);
|
|
46
|
+
if (!Number.isFinite(bytes) || bytes <= 0)
|
|
47
|
+
return null;
|
|
48
|
+
return Math.floor(bytes / (1024 ** 3));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
/** Round host RAM to Chrome's deviceMemory bucket {8,16,32}; null → 16. */
|
|
57
|
+
export function hostRamBucketGb() {
|
|
58
|
+
const gb = hostRamGb();
|
|
59
|
+
if (gb === null)
|
|
60
|
+
return 16;
|
|
61
|
+
if (gb >= 32)
|
|
62
|
+
return 32;
|
|
63
|
+
if (gb >= 16)
|
|
64
|
+
return 16;
|
|
65
|
+
return 8;
|
|
66
|
+
}
|
|
67
|
+
const MAC_RES_RE = /Resolution:\s*(\d+)\s*x\s*(\d+)/g;
|
|
68
|
+
const XRANDR_CUR_RE = /^\s*(\d+)x(\d+)[^\n]*\*/m;
|
|
69
|
+
/** Primary monitor (width, height) in CSS pixels, or null on failure. */
|
|
70
|
+
export function hostScreenSize() {
|
|
71
|
+
const plat = osPlatform();
|
|
72
|
+
try {
|
|
73
|
+
if (plat === "darwin")
|
|
74
|
+
return macScreenSize();
|
|
75
|
+
if (plat === "win32")
|
|
76
|
+
return windowsScreenSize();
|
|
77
|
+
if (plat === "linux")
|
|
78
|
+
return linuxScreenSize();
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
function macScreenSize() {
|
|
86
|
+
// `system_profiler SPDisplaysDataType` reports panel resolution, matching
|
|
87
|
+
// what the launcher's primary_monitor() returns post-scale.
|
|
88
|
+
let out;
|
|
89
|
+
try {
|
|
90
|
+
out = execFileSync("system_profiler", ["SPDisplaysDataType"], { stdio: ["ignore", "pipe", "ignore"], timeout: 4000 }).toString();
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
let best = null;
|
|
96
|
+
for (const m of out.matchAll(MAC_RES_RE)) {
|
|
97
|
+
const w = Number(m[1]);
|
|
98
|
+
const h = Number(m[2]);
|
|
99
|
+
if (!Number.isFinite(w) || !Number.isFinite(h))
|
|
100
|
+
continue;
|
|
101
|
+
if (best === null || w * h > best[0] * best[1])
|
|
102
|
+
best = [w, h];
|
|
103
|
+
}
|
|
104
|
+
return best;
|
|
105
|
+
}
|
|
106
|
+
function windowsScreenSize() {
|
|
107
|
+
try {
|
|
108
|
+
const out = execSync('powershell -NoProfile -Command ' +
|
|
109
|
+
'"Add-Type -AssemblyName System.Windows.Forms; ' +
|
|
110
|
+
'$s=[System.Windows.Forms.Screen]::PrimaryScreen.Bounds; ' +
|
|
111
|
+
'\\"$($s.Width)x$($s.Height)\\""', { stdio: ["ignore", "pipe", "ignore"], timeout: 4000 }).toString().trim();
|
|
112
|
+
const m = /^(\d+)x(\d+)$/.exec(out);
|
|
113
|
+
if (m) {
|
|
114
|
+
const w = Number(m[1]);
|
|
115
|
+
const h = Number(m[2]);
|
|
116
|
+
if (w > 0 && h > 0)
|
|
117
|
+
return [w, h];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
function linuxScreenSize() {
|
|
126
|
+
let out;
|
|
127
|
+
try {
|
|
128
|
+
out = execFileSync("xrandr", ["--query"], { stdio: ["ignore", "pipe", "ignore"], timeout: 4000 }).toString();
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
const m = XRANDR_CUR_RE.exec(out);
|
|
134
|
+
if (m) {
|
|
135
|
+
const w = Number(m[1]);
|
|
136
|
+
const h = Number(m[2]);
|
|
137
|
+
if (w > 0 && h > 0)
|
|
138
|
+
return [w, h];
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingUR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B,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAC,EACtC,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;IACvE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,CAAC,EAAE,CAAC;QACN,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;YAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type Browser as PatchrightBrowser } from "patchright";
|
|
2
|
+
import { Runtime, type ProgressCb } from "./runtime.js";
|
|
3
|
+
import { FingerprintLibrary, Profile } from "./profile.js";
|
|
4
|
+
import { type LaunchOptions, type BrowserSession } from "./browser.js";
|
|
5
|
+
import { type GeoInfo } from "./geo.js";
|
|
6
|
+
export interface ShardXOptions {
|
|
7
|
+
/** Where the engine, Widevine, and bundled fingerprint library live
|
|
8
|
+
* (defaults to the per-OS app-data dir). */
|
|
9
|
+
cacheDir?: string;
|
|
10
|
+
progress?: ProgressCb;
|
|
11
|
+
/** Per-profile user-data-dir root (cookies, IndexedDB, cache).
|
|
12
|
+
* Defaults to `./shardx-profiles/` next to the running script. */
|
|
13
|
+
profilesDir?: string;
|
|
14
|
+
}
|
|
15
|
+
export type LaunchInput = string | Profile | Record<string, unknown>;
|
|
16
|
+
export interface ShardXLaunchOptions extends LaunchOptions {
|
|
17
|
+
/** When `fingerprint` is omitted, pick a random profile filtered by this platform substring. */
|
|
18
|
+
platform?: string;
|
|
19
|
+
/** When true, re-pick hardware_concurrency / device_memory / platform_version before launch. */
|
|
20
|
+
randomize?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface ProxyCheckResult {
|
|
23
|
+
udpMs: number | null;
|
|
24
|
+
geo: GeoInfo;
|
|
25
|
+
wouldEnableQuic: boolean;
|
|
26
|
+
wouldSetWebrtc: "auto" | "tcp_only";
|
|
27
|
+
}
|
|
28
|
+
export declare class ShardX {
|
|
29
|
+
readonly runtime: Runtime;
|
|
30
|
+
readonly library: FingerprintLibrary;
|
|
31
|
+
private readonly browser;
|
|
32
|
+
constructor(opts?: ShardXOptions);
|
|
33
|
+
/** All bundled fingerprint ids, optionally filtered by `navigator.platform`.
|
|
34
|
+
* Auto-installs the fingerprint library on first call. */
|
|
35
|
+
listProfiles(opts?: {
|
|
36
|
+
platform?: string;
|
|
37
|
+
}): Promise<string[]>;
|
|
38
|
+
/** Pick a random profile from the library. Auto-installs on first call. */
|
|
39
|
+
randomProfile(opts?: {
|
|
40
|
+
platform?: string;
|
|
41
|
+
}): Promise<Profile>;
|
|
42
|
+
/**
|
|
43
|
+
* Launch a profile.
|
|
44
|
+
*
|
|
45
|
+
* @param fingerprint Profile id, `Profile` instance, plain dict, or `null`/omitted to pick random.
|
|
46
|
+
* @param opts.platform When picking random, filter by `navigator.platform` substring.
|
|
47
|
+
* @param opts.randomize When true, freshly randomise hw_concurrency / device_memory / platform_version.
|
|
48
|
+
* (Same logic the desktop launcher applies when re-picking a GPU.)
|
|
49
|
+
* All other options forwarded to `Browser.launch` (proxy, cdp, headless, webrtc, screenMode, …).
|
|
50
|
+
*/
|
|
51
|
+
launch(fingerprint?: LaunchInput | null, opts?: ShardXLaunchOptions): Promise<BrowserSession>;
|
|
52
|
+
/**
|
|
53
|
+
* Launch a profile AND connect patchright in one call. Returns an
|
|
54
|
+
* object with the patchright `Browser`, the raw `BrowserSession`, and
|
|
55
|
+
* a `close()` that tears both down.
|
|
56
|
+
*
|
|
57
|
+
* Requires `patchright` (`npm install patchright`) as an optional
|
|
58
|
+
* peer-dependency.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* const { browser, close } = await sdk.session({ fingerprint: "win-rtx4060", proxy: "socks5://…" });
|
|
62
|
+
* try {
|
|
63
|
+
* const page = await browser.contexts()[0].newPage();
|
|
64
|
+
* await page.goto("https://example.com");
|
|
65
|
+
* } finally {
|
|
66
|
+
* await close();
|
|
67
|
+
* }
|
|
68
|
+
*/
|
|
69
|
+
session(opts?: ShardXLaunchOptions & {
|
|
70
|
+
fingerprint?: LaunchInput | null;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
browser: PatchrightBrowser;
|
|
73
|
+
session: BrowserSession;
|
|
74
|
+
close: () => Promise<void>;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* Validate a proxy URL before binding it to a profile. Returns the same
|
|
78
|
+
* data the launcher uses to decide QUIC + WebRTC policy.
|
|
79
|
+
*/
|
|
80
|
+
checkProxy(proxyUrl: string): Promise<ProxyCheckResult>;
|
|
81
|
+
}
|
|
82
|
+
export { Runtime, defaultCacheDir, PUB_BASE, CHROMIUM_VERSION, hostSpec } from "./runtime.js";
|
|
83
|
+
export type { ProgressCb, HostSpec, Archive } from "./runtime.js";
|
|
84
|
+
export { Profile, FingerprintLibrary, userDataDir } from "./profile.js";
|
|
85
|
+
export { Browser, BrowserSession } from "./browser.js";
|
|
86
|
+
export type { LaunchOptions, WebRtcMode, ScreenMode } from "./browser.js";
|
|
87
|
+
export { parseProxy, probeUdp, proxyToArg } from "./proxy.js";
|
|
88
|
+
export type { ParsedProxy } from "./proxy.js";
|
|
89
|
+
export { randomizeHardware, randomizePlatformVersion, MAC_HW_CONFIGS, X86_CORES, MACOS_PLATFORM_VERSIONS, WINDOWS_PLATFORM_VERSIONS, LINUX_PLATFORM_VERSIONS, } from "./randomize.js";
|
|
90
|
+
export { hostLogicalCores, hostRamGb, hostRamBucketGb, hostScreenSize, } from "./host.js";
|
|
91
|
+
export type { Size } from "./host.js";
|
|
92
|
+
export { applyScreenStrategy, defaultScreenModeFor } from "./screen.js";
|
|
93
|
+
export type { ScreenStrategy } from "./screen.js";
|
|
94
|
+
export { geoCheckVia } from "./geo.js";
|
|
95
|
+
export type { GeoInfo, GeoProvider } from "./geo.js";
|
|
96
|
+
export { hasAutoFields, resolveAutoFields } from "./autoResolve.js";
|
|
97
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,OAAO,IAAI,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEzE,OAAO,EAAE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAW,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAGhF,OAAO,EAAe,KAAK,OAAO,EAAE,MAAM,UAAU,CAAC;AAErD,MAAM,WAAW,aAAa;IAC5B;iDAC6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB;uEACmE;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAErE,MAAM,WAAW,mBAAoB,SAAQ,aAAa;IACxD,gGAAgG;IAChG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gGAAgG;IAChG,SAAS,CAAC,E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,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACvD,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC9D,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,iBAAiB,EAAE,wBAAwB,EAC3C,cAAc,EAAE,SAAS,EACzB,uBAAuB,EAAE,yBAAyB,EAAE,uBAAuB,GAC5E,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,gBAAgB,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,GAC7D,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Top-level façade — bundles the runtime, fingerprint library, and
|
|
2
|
+
// browser launcher. Mirrors the Python `ShardX` class.
|
|
3
|
+
import { chromium } from "patchright";
|
|
4
|
+
import { Runtime } from "./runtime.js";
|
|
5
|
+
import { FingerprintLibrary, Profile } from "./profile.js";
|
|
6
|
+
import { Browser } from "./browser.js";
|
|
7
|
+
import { randomizeHardware, randomizePlatformVersion } from "./randomize.js";
|
|
8
|
+
import { parseProxy, probeUdp } from "./proxy.js";
|
|
9
|
+
import { geoCheckVia } from "./geo.js";
|
|
10
|
+
export class ShardX {
|
|
11
|
+
runtime;
|
|
12
|
+
library;
|
|
13
|
+
browser;
|
|
14
|
+
constructor(opts = {}) {
|
|
15
|
+
this.runtime = new Runtime(opts);
|
|
16
|
+
this.library = new FingerprintLibrary(this.runtime);
|
|
17
|
+
this.browser = new Browser(this.runtime);
|
|
18
|
+
}
|
|
19
|
+
/** All bundled fingerprint ids, optionally filtered by `navigator.platform`.
|
|
20
|
+
* Auto-installs the fingerprint library on first call. */
|
|
21
|
+
async listProfiles(opts = {}) {
|
|
22
|
+
await this.runtime.install();
|
|
23
|
+
return opts.platform ? Array.from(this.library.filter({ platform: opts.platform })) : this.library.ids();
|
|
24
|
+
}
|
|
25
|
+
/** Pick a random profile from the library. Auto-installs on first call. */
|
|
26
|
+
async randomProfile(opts = {}) {
|
|
27
|
+
const ids = await this.listProfiles(opts);
|
|
28
|
+
if (ids.length === 0) {
|
|
29
|
+
throw new Error(`No bundled profiles found${opts.platform ? ` for platform=${opts.platform}` : ""}. Did you call ensureInstalled()?`);
|
|
30
|
+
}
|
|
31
|
+
return this.library.load(ids[Math.floor(Math.random() * ids.length)]);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Launch a profile.
|
|
35
|
+
*
|
|
36
|
+
* @param fingerprint Profile id, `Profile` instance, plain dict, or `null`/omitted to pick random.
|
|
37
|
+
* @param opts.platform When picking random, filter by `navigator.platform` substring.
|
|
38
|
+
* @param opts.randomize When true, freshly randomise hw_concurrency / device_memory / platform_version.
|
|
39
|
+
* (Same logic the desktop launcher applies when re-picking a GPU.)
|
|
40
|
+
* All other options forwarded to `Browser.launch` (proxy, cdp, headless, webrtc, screenMode, …).
|
|
41
|
+
*/
|
|
42
|
+
async launch(fingerprint, opts = {}) {
|
|
43
|
+
await this.runtime.install();
|
|
44
|
+
let profile;
|
|
45
|
+
if (fingerprint == null) {
|
|
46
|
+
profile = await this.randomProfile({ platform: opts.platform });
|
|
47
|
+
}
|
|
48
|
+
else if (typeof fingerprint === "string") {
|
|
49
|
+
profile = this.library.load(fingerprint);
|
|
50
|
+
}
|
|
51
|
+
else if (fingerprint instanceof Profile) {
|
|
52
|
+
profile = fingerprint;
|
|
53
|
+
}
|
|
54
|
+
else if (typeof fingerprint === "object") {
|
|
55
|
+
profile = new Profile(fingerprint);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
throw new TypeError(`fingerprint must be string | Profile | object | null; got ${typeof fingerprint}`);
|
|
59
|
+
}
|
|
60
|
+
if (opts.randomize) {
|
|
61
|
+
randomizeHardware(profile.config, profile.id);
|
|
62
|
+
randomizePlatformVersion(profile.config);
|
|
63
|
+
}
|
|
64
|
+
const { platform: _p, randomize: _r, ...launchOpts } = opts;
|
|
65
|
+
return this.browser.launch(profile, launchOpts);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Launch a profile AND connect patchright in one call. Returns an
|
|
69
|
+
* object with the patchright `Browser`, the raw `BrowserSession`, and
|
|
70
|
+
* a `close()` that tears both down.
|
|
71
|
+
*
|
|
72
|
+
* Requires `patchright` (`npm install patchright`) as an optional
|
|
73
|
+
* peer-dependency.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* const { browser, close } = await sdk.session({ fingerprint: "win-rtx4060", proxy: "socks5://…" });
|
|
77
|
+
* try {
|
|
78
|
+
* const page = await browser.contexts()[0].newPage();
|
|
79
|
+
* await page.goto("https://example.com");
|
|
80
|
+
* } finally {
|
|
81
|
+
* await close();
|
|
82
|
+
* }
|
|
83
|
+
*/
|
|
84
|
+
async session(opts = {}) {
|
|
85
|
+
const { fingerprint, ...launchOpts } = opts;
|
|
86
|
+
const sess = await this.launch(fingerprint ?? null, { ...launchOpts, cdp: true });
|
|
87
|
+
if (!sess.cdpUrl) {
|
|
88
|
+
await sess.stop();
|
|
89
|
+
throw new Error("CDP endpoint unavailable — engine failed to expose remote-debugging port");
|
|
90
|
+
}
|
|
91
|
+
const browser = await chromium.connectOverCDP(sess.cdpUrl);
|
|
92
|
+
return {
|
|
93
|
+
browser,
|
|
94
|
+
session: sess,
|
|
95
|
+
async close() {
|
|
96
|
+
try {
|
|
97
|
+
await browser.close();
|
|
98
|
+
}
|
|
99
|
+
catch { /* ignore */ }
|
|
100
|
+
await sess.stop();
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Validate a proxy URL before binding it to a profile. Returns the same
|
|
106
|
+
* data the launcher uses to decide QUIC + WebRTC policy.
|
|
107
|
+
*/
|
|
108
|
+
async checkProxy(proxyUrl) {
|
|
109
|
+
const parsed = parseProxy(proxyUrl);
|
|
110
|
+
const udpMs = parsed.scheme === "socks5" ? await probeUdp(parsed) : null;
|
|
111
|
+
const geo = await geoCheckVia(parsed);
|
|
112
|
+
const udpOk = udpMs !== null;
|
|
113
|
+
return {
|
|
114
|
+
udpMs,
|
|
115
|
+
geo,
|
|
116
|
+
wouldEnableQuic: udpOk,
|
|
117
|
+
wouldSetWebrtc: udpOk ? "auto" : "tcp_only",
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export { Runtime, defaultCacheDir, PUB_BASE, CHROMIUM_VERSION, hostSpec } from "./runtime.js";
|
|
122
|
+
export { Profile, FingerprintLibrary, userDataDir } from "./profile.js";
|
|
123
|
+
export { Browser, BrowserSession } from "./browser.js";
|
|
124
|
+
export { parseProxy, probeUdp, proxyToArg } from "./proxy.js";
|
|
125
|
+
export { randomizeHardware, randomizePlatformVersion, MAC_HW_CONFIGS, X86_CORES, MACOS_PLATFORM_VERSIONS, WINDOWS_PLATFORM_VERSIONS, LINUX_PLATFORM_VERSIONS, } from "./randomize.js";
|
|
126
|
+
export { hostLogicalCores, hostRamGb, hostRamBucketGb, hostScreenSize, } from "./host.js";
|
|
127
|
+
export { applyScreenStrategy, defaultScreenModeFor } from "./screen.js";
|
|
128
|
+
export { geoCheckVia } from "./geo.js";
|
|
129
|
+
export { hasAutoFields, resolveAutoFields } from "./autoResolve.js";
|
|
130
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,uDAAuD;AACvD,OAAO,EAAE,QAAQ,EAAqC,MAAM,YAAY,CAAC;AAEzE,OAAO,EAAE,OAAO,EAAmB,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,OAAO,EAA2C,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,WAAW,EAAgB,MAAM,UAAU,CAAC;AA4BrD,MAAM,OAAO,MAAM;IACR,OAAO,CAAU;IACjB,OAAO,CAAqB;IACpB,OAAO,CAAU;IAElC,YAAY,OAAsB,EAAE;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED;+DAC2D;IAC3D,KAAK,CAAC,YAAY,CAAC,OAA8B,EAAE;QACjD,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,C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WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Runtime } from "./runtime.js";
|
|
2
|
+
export declare class Profile {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
config: Record<string, unknown>;
|
|
5
|
+
constructor(config: Record<string, unknown>, id?: string);
|
|
6
|
+
static fromFile(path: string): Profile;
|
|
7
|
+
/** Shallow merge: object values are merged one level deep, scalars replaced. */
|
|
8
|
+
withOverride(overrides: Record<string, unknown>): Profile;
|
|
9
|
+
get platform(): string;
|
|
10
|
+
get hasWebGPU(): boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class FingerprintLibrary {
|
|
13
|
+
private readonly runtime;
|
|
14
|
+
constructor(runtime: Runtime);
|
|
15
|
+
ids(): string[];
|
|
16
|
+
filter(opts?: {
|
|
17
|
+
platform?: string;
|
|
18
|
+
}): Generator<string>;
|
|
19
|
+
load(fingerprintId: string): Profile;
|
|
20
|
+
}
|
|
21
|
+
/** Per-profile state (cookies / IndexedDB / cache) — preserved across
|
|
22
|
+
* launches. Defaults to `./shardx-profiles/<id>/` next to the running
|
|
23
|
+
* script. Override per launch with `userDataDir` or per SDK with
|
|
24
|
+
* `new ShardX({ profilesDir })`. */
|
|
25
|
+
export declare function userDataDir(runtime: Runtime, profileId: string, base?: string): string;
|
|
26
|
+
//# sourceMappingURL=profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,qBAAa,OAAO;IAClB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAEpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM;IAKxD,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAMtC,gFAAgF;IAChF,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO;IAazD,IAAI,QAAQ,IAAI,MAAM,CAGrB;IAED,IAAI,SAAS,IAAI,OAAO,CAKvB;CACF;AAED,qBAAa,kBAAkB;IACjB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,OAAO;IAE7C,GAAG,IAAI,MAAM,EAAE;IAOd,MAAM,CAAC,IAAI,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,SAAS,CAAC,MAAM,CAAC;IAY5D,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO;CAQrC;AAED;;;qCAGqC;AACrC,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAKtF"}
|