ant0-browser 0.0.0-stage → 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/LICENSE +35 -0
- package/README.md +100 -2
- package/dist/chromium-version.d.ts +22 -0
- package/dist/chromium-version.d.ts.map +1 -0
- package/dist/chromium-version.js +22 -0
- package/dist/chromium-version.js.map +1 -0
- package/dist/download.d.ts +22 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +219 -0
- package/dist/download.js.map +1 -0
- package/dist/fingerprint.d.ts +213 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +375 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/fontpack.d.ts +13 -0
- package/dist/fontpack.d.ts.map +1 -0
- package/dist/fontpack.js +149 -0
- package/dist/fontpack.js.map +1 -0
- package/dist/fonts.d.ts +15 -0
- package/dist/fonts.d.ts.map +1 -0
- package/dist/fonts.js +86 -0
- package/dist/fonts.js.map +1 -0
- package/dist/geoip.d.ts +45 -0
- package/dist/geoip.d.ts.map +1 -0
- package/dist/geoip.js +289 -0
- package/dist/geoip.js.map +1 -0
- package/dist/geometry.d.ts +28 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +79 -0
- package/dist/geometry.js.map +1 -0
- package/dist/humanize.d.ts +20 -0
- package/dist/humanize.d.ts.map +1 -0
- package/dist/humanize.js +921 -0
- package/dist/humanize.js.map +1 -0
- package/dist/identity-persistence.d.ts +51 -0
- package/dist/identity-persistence.d.ts.map +1 -0
- package/dist/identity-persistence.js +301 -0
- package/dist/identity-persistence.js.map +1 -0
- package/dist/identity.d.ts +43 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +197 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +234 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +593 -0
- package/dist/index.js.map +1 -0
- package/dist/launch-ticket.d.ts +87 -0
- package/dist/launch-ticket.d.ts.map +1 -0
- package/dist/launch-ticket.js +233 -0
- package/dist/launch-ticket.js.map +1 -0
- package/dist/launchopts.d.ts +133 -0
- package/dist/launchopts.d.ts.map +1 -0
- package/dist/launchopts.js +204 -0
- package/dist/launchopts.js.map +1 -0
- package/dist/motion.d.ts +106 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +311 -0
- package/dist/motion.js.map +1 -0
- package/dist/motionscore.d.ts +57 -0
- package/dist/motionscore.d.ts.map +1 -0
- package/dist/motionscore.js +215 -0
- package/dist/motionscore.js.map +1 -0
- package/dist/persona-migration.d.ts +51 -0
- package/dist/persona-migration.d.ts.map +1 -0
- package/dist/persona-migration.js +95 -0
- package/dist/persona-migration.js.map +1 -0
- package/dist/persona-profile-v2.d.ts +155 -0
- package/dist/persona-profile-v2.d.ts.map +1 -0
- package/dist/persona-profile-v2.js +421 -0
- package/dist/persona-profile-v2.js.map +1 -0
- package/dist/population-model.d.ts +42 -0
- package/dist/population-model.d.ts.map +1 -0
- package/dist/population-model.js +224 -0
- package/dist/population-model.js.map +1 -0
- package/dist/release-fetch.d.ts +70 -0
- package/dist/release-fetch.d.ts.map +1 -0
- package/dist/release-fetch.js +392 -0
- package/dist/release-fetch.js.map +1 -0
- package/dist/release.d.ts +16 -0
- package/dist/release.d.ts.map +1 -0
- package/dist/release.js +26 -0
- package/dist/release.js.map +1 -0
- package/dist/render.d.ts +38 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +104 -0
- package/dist/render.js.map +1 -0
- package/dist/shaderdialect.d.ts +33 -0
- package/dist/shaderdialect.d.ts.map +1 -0
- package/dist/shaderdialect.js +46 -0
- package/dist/shaderdialect.js.map +1 -0
- package/dist/template-selection.d.ts +14 -0
- package/dist/template-selection.d.ts.map +1 -0
- package/dist/template-selection.js +65 -0
- package/dist/template-selection.js.map +1 -0
- package/dist/warnings.d.ts +19 -0
- package/dist/warnings.d.ts.map +1 -0
- package/dist/warnings.js +159 -0
- package/dist/warnings.js.map +1 -0
- package/dist/widevine.d.ts +44 -0
- package/dist/widevine.d.ts.map +1 -0
- package/dist/widevine.js +202 -0
- package/dist/widevine.js.map +1 -0
- package/package.json +56 -4
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** The engine switch; the value is the five-segment ticket. */
|
|
2
|
+
export declare const LAUNCH_TICKET_SWITCH = "ant0-launch";
|
|
3
|
+
/** Exit code of an engine that refused its ticket (or got none). */
|
|
4
|
+
export declare const LAUNCH_TICKET_EXIT_CODE = 90;
|
|
5
|
+
/** Error code carried by {@link LaunchTicketRejectedError}. */
|
|
6
|
+
export declare const LAUNCH_TICKET_REJECTED_CODE = "engine.launch_ticket_rejected";
|
|
7
|
+
/** Env override for the engine's release version when it cannot be inferred from the install. */
|
|
8
|
+
export declare const ENGINE_VERSION_ENV = "ANT0_BROWSER_ENGINE_VERSION";
|
|
9
|
+
/** Launch options added by the ticket check. */
|
|
10
|
+
export interface LaunchTicketOption {
|
|
11
|
+
/**
|
|
12
|
+
* The `--ant0-launch=` value. Omitted: the SDK fetches one from the local daemon when it can find
|
|
13
|
+
* one (see module comment) and otherwise launches without a ticket. `false`: never contact a
|
|
14
|
+
* daemon (the caller passes the switch in `args` itself, or knows the engine is a test build).
|
|
15
|
+
*/
|
|
16
|
+
launchTicket?: string | false;
|
|
17
|
+
/**
|
|
18
|
+
* Release version the ticket must name (`<chromium>-ant0.<n>`). Default: the install's
|
|
19
|
+
* `.release.json`, a `<version>/browser/` path component, or `ANT0_BROWSER_ENGINE_VERSION`.
|
|
20
|
+
*/
|
|
21
|
+
engineVersion?: string;
|
|
22
|
+
}
|
|
23
|
+
/** The engine exited with code 90 because its launch ticket was missing or invalid. */
|
|
24
|
+
export declare class LaunchTicketRejectedError extends Error {
|
|
25
|
+
/** The engine's reason: missing, malformed, unknown_kid, bad_signature, past_grace, bad_claim_signature, claim_mismatch, claim_expired, wrong_engine. */
|
|
26
|
+
readonly reason: string;
|
|
27
|
+
readonly code = "engine.launch_ticket_rejected";
|
|
28
|
+
constructor(
|
|
29
|
+
/** The engine's reason: missing, malformed, unknown_kid, bad_signature, past_grace, bad_claim_signature, claim_mismatch, claim_expired, wrong_engine. */
|
|
30
|
+
reason: string, detail?: string);
|
|
31
|
+
}
|
|
32
|
+
/** The engine's reason if `text` (stderr, or an error message quoting it) contains the rejection line. */
|
|
33
|
+
export declare function launchTicketRejection(text: string | undefined | null): string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Rethrow a launch failure as {@link LaunchTicketRejectedError} when the browser's stderr (quoted by
|
|
36
|
+
* Playwright in the error message) carries the engine's rejection line; otherwise rethrow as is.
|
|
37
|
+
*/
|
|
38
|
+
export declare function rethrowIfTicketRejected(error: unknown): never;
|
|
39
|
+
/** True when the caller already put `--ant0-launch=` in the engine args. */
|
|
40
|
+
export declare function hasLaunchTicketArg(args: readonly string[]): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The release version an installed engine identifies as: `.release.json` next to its `browser/`
|
|
43
|
+
* directory (what the SDK's installer and ant0d write), else a `<version>` path component, else
|
|
44
|
+
* `ANT0_BROWSER_ENGINE_VERSION`. Undefined for a bare binary (tests, hand-built trees).
|
|
45
|
+
*/
|
|
46
|
+
export declare function inferEngineVersion(executable: string, env?: NodeJS.ProcessEnv): string | undefined;
|
|
47
|
+
export interface DaemonLocation {
|
|
48
|
+
baseUrl: string;
|
|
49
|
+
token: string;
|
|
50
|
+
}
|
|
51
|
+
/** The data folder, as ant0d/CLI resolve it (explicit env, platform default, legacy `~/.ant0`). */
|
|
52
|
+
export declare function resolveDaemonHome(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, userHome?: string): string;
|
|
53
|
+
/** Where a running daemon is, or undefined when there is no token to send (= not running). */
|
|
54
|
+
export declare function discoverDaemon(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, userHome?: string): DaemonLocation | undefined;
|
|
55
|
+
/** Thrown by {@link fetchLaunchTicket} when the daemon answers but will not issue a ticket. */
|
|
56
|
+
export declare class LaunchTicketUnavailableError extends Error {
|
|
57
|
+
/** Daemon error code, e.g. `licence.required`, `workspace.suspended`, or `http_<status>`. */
|
|
58
|
+
readonly code: string;
|
|
59
|
+
constructor(
|
|
60
|
+
/** Daemon error code, e.g. `licence.required`, `workspace.suspended`, or `http_<status>`. */
|
|
61
|
+
code: string, message: string);
|
|
62
|
+
}
|
|
63
|
+
export interface FetchLaunchTicketOptions {
|
|
64
|
+
timeoutMs?: number;
|
|
65
|
+
/** Test seam. */
|
|
66
|
+
fetchImpl?: typeof fetch;
|
|
67
|
+
}
|
|
68
|
+
/** `GET /v1/licence/ticket?engine=<engine>` with the daemon token; resolves to the `launch` value. */
|
|
69
|
+
export declare function fetchLaunchTicket(engine: string, daemon: DaemonLocation, opts?: FetchLaunchTicketOptions): Promise<string>;
|
|
70
|
+
export interface ResolveLaunchTicketOptions extends LaunchTicketOption {
|
|
71
|
+
/** Resolved engine binary (for {@link inferEngineVersion}). */
|
|
72
|
+
executable: string;
|
|
73
|
+
/** Engine args assembled so far (a caller-supplied `--ant0-launch=` wins). */
|
|
74
|
+
args: readonly string[];
|
|
75
|
+
quiet?: boolean;
|
|
76
|
+
env?: NodeJS.ProcessEnv;
|
|
77
|
+
fetchImpl?: typeof fetch;
|
|
78
|
+
timeoutMs?: number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The `--ant0-launch=` arg to append: the caller's ticket, or one fetched from the local daemon for
|
|
82
|
+
* the engine's release version. Empty when the caller disabled it, already passed the switch, no
|
|
83
|
+
* version can be inferred, no daemon is reachable, or the daemon refused (a note goes to stderr
|
|
84
|
+
* unless `quiet`; the engine's own exit-90 then names the outcome).
|
|
85
|
+
*/
|
|
86
|
+
export declare function resolveLaunchTicketArgs(opts: ResolveLaunchTicketOptions): Promise<string[]>;
|
|
87
|
+
//# sourceMappingURL=launch-ticket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch-ticket.d.ts","sourceRoot":"","sources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
+
// Since patch 0037 the engine refuses to start without `--ant0-launch=<ticket>`: a licence token
|
|
4
|
+
// signed by the Ant0 server, plus a 15-minute claim the local device signed, bound to the engine's
|
|
5
|
+
// release version. The SDK never mints tickets (it has no device key); it either passes the one the
|
|
6
|
+
// caller hands in (`launchTicket`) or asks the local daemon for one
|
|
7
|
+
// (`GET /v1/licence/ticket?engine=<version>`) when a daemon is reachable. Without either the launch
|
|
8
|
+
// proceeds and the engine exits with code 90 and `ant0: launch ticket invalid (<reason>)` on stderr,
|
|
9
|
+
// which the SDK surfaces as a {@link LaunchTicketRejectedError} (`code: "engine.launch_ticket_rejected"`).
|
|
10
|
+
//
|
|
11
|
+
// Daemon discovery follows the CLI (`@ant0/api-client` `discoverDaemon`): `ANT0_URL` (+ `ANT0_TOKEN`)
|
|
12
|
+
// when set; else the data folder (`ANT0_HOME`, the platform default, or a legacy `~/.ant0`) gives
|
|
13
|
+
// `ant0d.pid` (port/host) and `ant0d.token`; `ANT0D_HOST`/`ANT0D_PORT` are the fallbacks. No token
|
|
14
|
+
// means no daemon, and no request is made.
|
|
15
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
16
|
+
import { homedir } from "node:os";
|
|
17
|
+
import { basename, dirname, join, posix, win32 } from "node:path";
|
|
18
|
+
/** The engine switch; the value is the five-segment ticket. */
|
|
19
|
+
export const LAUNCH_TICKET_SWITCH = "ant0-launch";
|
|
20
|
+
/** Exit code of an engine that refused its ticket (or got none). */
|
|
21
|
+
export const LAUNCH_TICKET_EXIT_CODE = 90;
|
|
22
|
+
/** Error code carried by {@link LaunchTicketRejectedError}. */
|
|
23
|
+
export const LAUNCH_TICKET_REJECTED_CODE = "engine.launch_ticket_rejected";
|
|
24
|
+
/** Env override for the engine's release version when it cannot be inferred from the install. */
|
|
25
|
+
export const ENGINE_VERSION_ENV = "ANT0_BROWSER_ENGINE_VERSION";
|
|
26
|
+
const STDERR_LINE = /ant0: launch ticket invalid \(([a-z_]+)\)/;
|
|
27
|
+
const RELEASE_VERSION = /^\d+\.\d+\.\d+\.\d+-ant0\.\d+$/;
|
|
28
|
+
const DEFAULT_HOST = "127.0.0.1";
|
|
29
|
+
const DEFAULT_PORT = 27100;
|
|
30
|
+
const DEFAULT_TIMEOUT_MS = 3000;
|
|
31
|
+
/** The engine exited with code 90 because its launch ticket was missing or invalid. */
|
|
32
|
+
export class LaunchTicketRejectedError extends Error {
|
|
33
|
+
reason;
|
|
34
|
+
code = LAUNCH_TICKET_REJECTED_CODE;
|
|
35
|
+
constructor(
|
|
36
|
+
/** The engine's reason: missing, malformed, unknown_kid, bad_signature, past_grace, bad_claim_signature, claim_mismatch, claim_expired, wrong_engine. */
|
|
37
|
+
reason, detail) {
|
|
38
|
+
super(`ant0-browser: the engine rejected its launch ticket (${reason}). ` +
|
|
39
|
+
(reason === "missing"
|
|
40
|
+
? "Start it through ant0d, pass launchTicket, or run a daemon the SDK can reach (ANT0_URL / ANT0_HOME)."
|
|
41
|
+
: "Ask the daemon for a fresh ticket (GET /v1/licence/ticket) for this exact engine version.") +
|
|
42
|
+
(detail ? `\n${detail}` : ""));
|
|
43
|
+
this.reason = reason;
|
|
44
|
+
this.name = "LaunchTicketRejectedError";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** The engine's reason if `text` (stderr, or an error message quoting it) contains the rejection line. */
|
|
48
|
+
export function launchTicketRejection(text) {
|
|
49
|
+
if (!text)
|
|
50
|
+
return undefined;
|
|
51
|
+
const m = STDERR_LINE.exec(text);
|
|
52
|
+
return m ? m[1] : undefined;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Rethrow a launch failure as {@link LaunchTicketRejectedError} when the browser's stderr (quoted by
|
|
56
|
+
* Playwright in the error message) carries the engine's rejection line; otherwise rethrow as is.
|
|
57
|
+
*/
|
|
58
|
+
export function rethrowIfTicketRejected(error) {
|
|
59
|
+
const reason = launchTicketRejection(error instanceof Error ? error.message : String(error));
|
|
60
|
+
if (reason)
|
|
61
|
+
throw new LaunchTicketRejectedError(reason, `Playwright: ${error.message.split("\n")[0]}`);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
/** True when the caller already put `--ant0-launch=` in the engine args. */
|
|
65
|
+
export function hasLaunchTicketArg(args) {
|
|
66
|
+
return args.some((a) => a === `--${LAUNCH_TICKET_SWITCH}` || a.startsWith(`--${LAUNCH_TICKET_SWITCH}=`));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The release version an installed engine identifies as: `.release.json` next to its `browser/`
|
|
70
|
+
* directory (what the SDK's installer and ant0d write), else a `<version>` path component, else
|
|
71
|
+
* `ANT0_BROWSER_ENGINE_VERSION`. Undefined for a bare binary (tests, hand-built trees).
|
|
72
|
+
*/
|
|
73
|
+
export function inferEngineVersion(executable, env = process.env) {
|
|
74
|
+
let dir = dirname(executable);
|
|
75
|
+
for (let depth = 0; depth < 6; depth++) {
|
|
76
|
+
const file = join(dir, ".release.json");
|
|
77
|
+
if (existsSync(file)) {
|
|
78
|
+
try {
|
|
79
|
+
const version = JSON.parse(readFileSync(file, "utf8")).version;
|
|
80
|
+
if (typeof version === "string" && RELEASE_VERSION.test(version))
|
|
81
|
+
return version;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
/* fall through to the path heuristics */
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (RELEASE_VERSION.test(basename(dir)))
|
|
88
|
+
return basename(dir);
|
|
89
|
+
const parent = dirname(dir);
|
|
90
|
+
if (parent === dir)
|
|
91
|
+
break;
|
|
92
|
+
dir = parent;
|
|
93
|
+
}
|
|
94
|
+
const fromEnv = env[ENGINE_VERSION_ENV]?.trim();
|
|
95
|
+
return fromEnv && RELEASE_VERSION.test(fromEnv) ? fromEnv : undefined;
|
|
96
|
+
}
|
|
97
|
+
function isLoopback(host) {
|
|
98
|
+
const h = host.replace(/^\[|\]$/g, "").toLowerCase();
|
|
99
|
+
return h === "localhost" || h === "::1" || h.startsWith("127.");
|
|
100
|
+
}
|
|
101
|
+
function homeExists(dir) {
|
|
102
|
+
return existsSync(join(dir, "ant0.db")) || existsSync(join(dir, "profiles"));
|
|
103
|
+
}
|
|
104
|
+
function readToken(file) {
|
|
105
|
+
try {
|
|
106
|
+
const token = readFileSync(file, "utf8").trim();
|
|
107
|
+
return token.length > 0 ? token : undefined;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** The data folder, as ant0d/CLI resolve it (explicit env, platform default, legacy `~/.ant0`). */
|
|
114
|
+
export function resolveDaemonHome(env = process.env, platform = process.platform, userHome = homedir()) {
|
|
115
|
+
const explicit = env.ANT0_HOME?.trim();
|
|
116
|
+
if (explicit)
|
|
117
|
+
return explicit;
|
|
118
|
+
const p = platform === "win32" ? win32 : posix;
|
|
119
|
+
let def;
|
|
120
|
+
if (platform === "win32") {
|
|
121
|
+
def = env.LOCALAPPDATA ? win32.join(env.LOCALAPPDATA, "Ant0") : win32.join(userHome, "AppData", "Local", "Ant0");
|
|
122
|
+
}
|
|
123
|
+
else if (platform === "darwin") {
|
|
124
|
+
def = posix.join(userHome, "Library", "Application Support", "Ant0");
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
def = env.XDG_DATA_HOME ? posix.join(env.XDG_DATA_HOME, "ant0") : posix.join(userHome, ".local", "share", "ant0");
|
|
128
|
+
}
|
|
129
|
+
const legacy = p.join(userHome, ".ant0");
|
|
130
|
+
return !homeExists(def) && homeExists(legacy) ? legacy : def;
|
|
131
|
+
}
|
|
132
|
+
/** Where a running daemon is, or undefined when there is no token to send (= not running). */
|
|
133
|
+
export function discoverDaemon(env = process.env, platform = process.platform, userHome = homedir()) {
|
|
134
|
+
const home = resolveDaemonHome(env, platform, userHome);
|
|
135
|
+
const token = env.ANT0_TOKEN?.trim() || readToken(join(home, "ant0d.token"));
|
|
136
|
+
if (!token)
|
|
137
|
+
return undefined;
|
|
138
|
+
const url = env.ANT0_URL?.trim();
|
|
139
|
+
if (url)
|
|
140
|
+
return { baseUrl: url.replace(/\/+$/, ""), token };
|
|
141
|
+
let host;
|
|
142
|
+
let port;
|
|
143
|
+
try {
|
|
144
|
+
const pid = JSON.parse(readFileSync(join(home, "ant0d.pid"), "utf8"));
|
|
145
|
+
if (typeof pid.port === "number" && Number.isInteger(pid.port) && pid.port > 0 && pid.port <= 65535)
|
|
146
|
+
port = pid.port;
|
|
147
|
+
if (typeof pid.host === "string" && pid.host.length > 0 && isLoopback(pid.host))
|
|
148
|
+
host = pid.host;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
/* no pid file: fall back to the environment */
|
|
152
|
+
}
|
|
153
|
+
const envPort = Number(env.ANT0D_PORT);
|
|
154
|
+
port ??= Number.isInteger(envPort) && envPort > 0 && envPort <= 65535 ? envPort : DEFAULT_PORT;
|
|
155
|
+
host ??= env.ANT0D_HOST && isLoopback(env.ANT0D_HOST) ? env.ANT0D_HOST : DEFAULT_HOST;
|
|
156
|
+
const h = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
157
|
+
return { baseUrl: `http://${h}:${port}`, token };
|
|
158
|
+
}
|
|
159
|
+
/** Thrown by {@link fetchLaunchTicket} when the daemon answers but will not issue a ticket. */
|
|
160
|
+
export class LaunchTicketUnavailableError extends Error {
|
|
161
|
+
code;
|
|
162
|
+
constructor(
|
|
163
|
+
/** Daemon error code, e.g. `licence.required`, `workspace.suspended`, or `http_<status>`. */
|
|
164
|
+
code, message) {
|
|
165
|
+
super(`ant0-browser: the daemon did not issue a launch ticket (${code}): ${message}`);
|
|
166
|
+
this.code = code;
|
|
167
|
+
this.name = "LaunchTicketUnavailableError";
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** `GET /v1/licence/ticket?engine=<engine>` with the daemon token; resolves to the `launch` value. */
|
|
171
|
+
export async function fetchLaunchTicket(engine, daemon, opts = {}) {
|
|
172
|
+
const doFetch = opts.fetchImpl ?? fetch;
|
|
173
|
+
const controller = new AbortController();
|
|
174
|
+
const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
175
|
+
try {
|
|
176
|
+
const res = await doFetch(`${daemon.baseUrl}/v1/licence/ticket?engine=${encodeURIComponent(engine)}`, {
|
|
177
|
+
headers: { Authorization: `Bearer ${daemon.token}`, Accept: "application/json" },
|
|
178
|
+
signal: controller.signal,
|
|
179
|
+
});
|
|
180
|
+
const body = (await res.json().catch(() => undefined));
|
|
181
|
+
if (!res.ok) {
|
|
182
|
+
const code = typeof body?.error?.code === "string" ? body.error.code : `http_${res.status}`;
|
|
183
|
+
const message = typeof body?.error?.message === "string" ? body.error.message : res.statusText;
|
|
184
|
+
throw new LaunchTicketUnavailableError(code, message);
|
|
185
|
+
}
|
|
186
|
+
if (typeof body?.launch !== "string" || body.launch.split(".").length !== 5) {
|
|
187
|
+
throw new LaunchTicketUnavailableError("bad_response", "response has no five-segment `launch`");
|
|
188
|
+
}
|
|
189
|
+
return body.launch;
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
clearTimeout(timer);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The `--ant0-launch=` arg to append: the caller's ticket, or one fetched from the local daemon for
|
|
197
|
+
* the engine's release version. Empty when the caller disabled it, already passed the switch, no
|
|
198
|
+
* version can be inferred, no daemon is reachable, or the daemon refused (a note goes to stderr
|
|
199
|
+
* unless `quiet`; the engine's own exit-90 then names the outcome).
|
|
200
|
+
*/
|
|
201
|
+
export async function resolveLaunchTicketArgs(opts) {
|
|
202
|
+
if (opts.launchTicket === false || hasLaunchTicketArg(opts.args))
|
|
203
|
+
return [];
|
|
204
|
+
if (typeof opts.launchTicket === "string") {
|
|
205
|
+
if (opts.launchTicket.split(".").length !== 5) {
|
|
206
|
+
throw new TypeError("launchTicket must be the five-segment `lic.claim.csig` value the daemon issues");
|
|
207
|
+
}
|
|
208
|
+
return [`--${LAUNCH_TICKET_SWITCH}=${opts.launchTicket}`];
|
|
209
|
+
}
|
|
210
|
+
const env = opts.env ?? process.env;
|
|
211
|
+
const note = (msg) => {
|
|
212
|
+
if (!opts.quiet && env.ANT0_BROWSER_NO_WARN === undefined)
|
|
213
|
+
process.stderr.write(`[ant0-browser] [launch-ticket] ${msg}\n`);
|
|
214
|
+
};
|
|
215
|
+
const engine = opts.engineVersion ?? inferEngineVersion(opts.executable, env);
|
|
216
|
+
if (!engine)
|
|
217
|
+
return []; // bare binary: nothing to bind a ticket to (tests, hand-built trees)
|
|
218
|
+
const daemon = discoverDaemon(env);
|
|
219
|
+
if (!daemon) {
|
|
220
|
+
note(`no ant0d found (no token under ${resolveDaemonHome(env)}); launching ${engine} without a ticket`);
|
|
221
|
+
return [];
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
const launch = await fetchLaunchTicket(engine, daemon, { fetchImpl: opts.fetchImpl, timeoutMs: opts.timeoutMs });
|
|
225
|
+
return [`--${LAUNCH_TICKET_SWITCH}=${launch}`];
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
const why = error instanceof LaunchTicketUnavailableError ? error.code : error?.name === "AbortError" ? "timeout" : String(error);
|
|
229
|
+
note(`${daemon.baseUrl} issued no ticket for ${engine} (${why}); launching without one`);
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=launch-ticket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch-ticket.js","sourceRoot":"","sources":["../src/launch-ticket.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,EAAE;AACF,iGAAiG;AACjG,mGAAmG;AACnG,oGAAoG;AACpG,oEAAoE;AACpE,oGAAoG;AACpG,qGAAqG;AACrG,2GAA2G;AAC3G,EAAE;AACF,sGAAsG;AACtG,kGAAkG;AAClG,mGAAmG;AACnG,2CAA2C;AAE3C,OAAO,EAAE,UA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C,CAAC;QACxG,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QACjH,OAAO,CAAC,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAAC,CAAC;IACjD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,GAAG,GAAG,KAAK,YAAY,4BAA4B,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAE,KAAe,EAAE,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7I,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,yBAAyB,MAAM,KAAK,GAAG,0BAA0B,CAAC,CAAC;QACzF,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/** A Playwright proxy descriptor. */
|
|
2
|
+
export interface PwProxy {
|
|
3
|
+
server?: string;
|
|
4
|
+
username?: string;
|
|
5
|
+
password?: string;
|
|
6
|
+
bypass?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Privacy Sandbox + intrusive web APIs a de-Googled stealth build should not expose (a build that
|
|
9
|
+
* claims de-Googled while still answering document.browsingTopics()/navigator.runAdAuction is a
|
|
10
|
+
* self-contradictory, pivotable fingerprint). All are runtime base::Features, so disabling needs
|
|
11
|
+
* no rebuild.
|
|
12
|
+
*
|
|
13
|
+
* WebUSB is deliberately NOT in this list. It is not a Privacy Sandbox feature - it is a device
|
|
14
|
+
* API that ships alongside Web Serial, WebHID and Web Bluetooth under identical secure-context
|
|
15
|
+
* gating. Disabling only WebUSB left navigator.usb absent while serial/hid/bluetooth stayed
|
|
16
|
+
* present, a combination no real Chromium produces; measured against stock Chrome on the same
|
|
17
|
+
* host, that split was the single flagged difference in the device-API family. Presence leaks
|
|
18
|
+
* nothing on its own - the API is permission-gated and enumerates no device without a user
|
|
19
|
+
* gesture - so exposing it costs no privacy and removes a hard coherence tell. */
|
|
20
|
+
export declare const PRIVACY_SANDBOX_FEATURES: readonly ["BrowsingTopics", "BrowsingTopicsDocumentAPI", "Fledge", "InterestGroupStorage", "PrivateAggregationApi", "SharedStorageAPI", "FencedFrames"];
|
|
21
|
+
/** Chromium honors only the LAST --enable-features / --disable-features on the command line (they
|
|
22
|
+
* do NOT concatenate), so multiple occurrences clobber each other. Collapse all of each into a
|
|
23
|
+
* single flag (order-preserving, de-duped) so defaults from different layers + the user's own flags
|
|
24
|
+
* coexist. */
|
|
25
|
+
export declare function mergeFeatureFlags(args: string[]): string[];
|
|
26
|
+
/** Disable Privacy Sandbox + intrusive APIs (runtime, no rebuild). */
|
|
27
|
+
export declare function privacySandboxArgs(): string[];
|
|
28
|
+
/** Behind a proxy, real Chrome cannot use QUIC/HTTP3 (a SOCKS5/HTTP proxy carries only TCP), so it
|
|
29
|
+
* falls back to TCP. Disable QUIC when a proxy is configured so no HTTP/3 UDP is attempted —
|
|
30
|
+
* coherent with proxied Chrome, and a guarantee no UDP egresses around the proxy. No proxy -> leave
|
|
31
|
+
* QUIC on (real Chrome uses it). */
|
|
32
|
+
export declare function quicArgs(proxy: PwProxy | undefined): string[];
|
|
33
|
+
/** Carry WebRTC's UDP through the SOCKS5 proxy with UDP ASSOCIATE (RFC 1928 §7) instead of letting
|
|
34
|
+
* it egress on the host's own path.
|
|
35
|
+
*
|
|
36
|
+
* This is the transport the {@link webrtcDefaultDenyArgs} note asks for. That default sets
|
|
37
|
+
* `disable_non_proxied_udp`, which on stock Chromium means "no UDP at all", because stock Chromium
|
|
38
|
+
* has no way to proxy a datagram — so peer connections that genuinely need UDP simply fail. With
|
|
39
|
+
* this option the engine opens a UDP association through the proxy and relays every datagram over
|
|
40
|
+
* it, so UDP works AND still leaves from the proxy's address. The two compose: measured against the
|
|
41
|
+
* proxy's own log, the association is established with the deny policy in force, so enabling this
|
|
42
|
+
* does not require weakening the policy.
|
|
43
|
+
*
|
|
44
|
+
* Emitted only for a `socks5://` proxy. UDP ASSOCIATE is a SOCKS5 command — SOCKS4 has no
|
|
45
|
+
* equivalent, and an HTTP proxy carries only TCP — so with any other scheme the switch would be
|
|
46
|
+
* accepted and silently do nothing, which is worse than not sending it.
|
|
47
|
+
*
|
|
48
|
+
* Requires engine support; older binaries ignore the switch. Off by default: it is a real
|
|
49
|
+
* behaviour change (UDP starts flowing where the deny policy previously stopped it), and a proxy
|
|
50
|
+
* that advertises SOCKS5 but refuses ASSOCIATE — common among cheap residential pools — leaves the
|
|
51
|
+
* connection no worse off but no better either. */
|
|
52
|
+
export declare function socks5UdpArgs(socks5Udp: boolean | undefined, proxy: PwProxy | undefined): string[];
|
|
53
|
+
/** Default WebRTC to disable_non_proxied_udp, so no UDP can egress around the proxy.
|
|
54
|
+
*
|
|
55
|
+
* This used to be skipped whenever `webrtcIp` was set, on the theory that the engine's srflx
|
|
56
|
+
* fabrication already covered WebRTC. It does not — the two defend different things:
|
|
57
|
+
*
|
|
58
|
+
* - fabrication rewrites what the browser *reports*, which beats a page that reads the candidate;
|
|
59
|
+
* - this policy stops UDP *leaving the machine*, which beats a server that watches where packets
|
|
60
|
+
* arrive from.
|
|
61
|
+
*
|
|
62
|
+
* A page that sets `iceTransportPolicy: "relay"` forces the browser to talk to its own TURN server.
|
|
63
|
+
* TURN prefers UDP and an HTTP/SOCKS proxy carries only TCP, so that UDP left on the host's own
|
|
64
|
+
* path and the TURN server read the real public address straight off the packet — no candidate
|
|
65
|
+
* involved, so fabricating one changed nothing. Reported by a customer whose session was flagged
|
|
66
|
+
* for location spoofing with an otherwise perfectly coherent persona.
|
|
67
|
+
*
|
|
68
|
+
* Worse, `geoip: true` sets `webrtcIp` for you, so the more carefully a caller configured for
|
|
69
|
+
* coherence the more likely they had silently lost this. Now only an explicit policy from the
|
|
70
|
+
* caller suppresses it.
|
|
71
|
+
*
|
|
72
|
+
* Note this is a real trade-off, not a free win: denying non-proxied UDP means peer connections
|
|
73
|
+
* that genuinely need UDP will not establish. Callers who need working WebRTC through a proxy want
|
|
74
|
+
* a transport that actually carries UDP (SOCKS5 with UDP ASSOCIATE, or a full tunnel) and can set
|
|
75
|
+
* their own policy to opt out. */
|
|
76
|
+
/**
|
|
77
|
+
* Switches to expose `navigator.bluetooth` on Linux hosts (empty elsewhere).
|
|
78
|
+
*
|
|
79
|
+
* Web Bluetooth is compiled into the engine but runtime-disabled on Linux only:
|
|
80
|
+
* Chromium's runtime_enabled_features.json5 gives WebBluetooth status "stable" on Win/Mac/Android/
|
|
81
|
+
* ChromeOS and lets Linux fall through to "default": "experimental", and content_features.cc
|
|
82
|
+
* declares kWebBluetooth FEATURE_DISABLED_BY_DEFAULT. So a Linux host serving a Windows persona
|
|
83
|
+
* reports navigator.usb, navigator.serial and navigator.hid but NOT navigator.bluetooth - a
|
|
84
|
+
* combination no real Windows Chrome produces, and an OS-origin tell that survives every string
|
|
85
|
+
* spoof. One flag restores it on the shipped binary; no rebuild is involved.
|
|
86
|
+
*
|
|
87
|
+
* Verified against Chromium 150's bluetooth.idl: getDevices() is gated on WebBluetoothGetDevices
|
|
88
|
+
* and requestLEScan()/onadvertisementreceived on WebBluetoothScanning, both "experimental", so
|
|
89
|
+
* real stable Chrome exposes exactly {constructor, getAvailability, requestDevice} - which is what
|
|
90
|
+
* this flag produces. getAvailability() resolves false and requestDevice() rejects NotFoundError
|
|
91
|
+
* on a machine with no adapter, matching a real desktop without Bluetooth hardware.
|
|
92
|
+
*/
|
|
93
|
+
export declare function webBluetoothArgs(): string[];
|
|
94
|
+
export declare function webrtcDefaultDenyArgs(args: string[], _webrtcIp?: unknown): string[];
|
|
95
|
+
/** Switches to load unpacked extensions. Chromium needs BOTH --load-extension=<dirs> and
|
|
96
|
+
* --disable-extensions-except=<dirs> (the latter keeps the listed extensions enabled while
|
|
97
|
+
* everything else stays off). `paths` is a list of unpacked-extension directories. */
|
|
98
|
+
export declare function extensionArgs(paths?: string[]): string[];
|
|
99
|
+
/** First-run/UX hygiene switches for a DIRECT launch (`serve()` / `launchPlan()`).
|
|
100
|
+
*
|
|
101
|
+
* Playwright adds these itself on `launch()`, so a Playwright-driven browser never shows the
|
|
102
|
+
* first-run UI. A direct spawn gets none of that, and the ungoogled-chromium base then opens
|
|
103
|
+
* `chrome://ungoogled-first-run` ("ungoogled-chromium first run page", empty body) in the first
|
|
104
|
+
* tab whenever the caller passes no start URL, plus the default-browser prompt and the search
|
|
105
|
+
* engine choice screen in headed mode. These are plain UI switches, not `base::Feature` toggles:
|
|
106
|
+
* they change nothing a page can observe, so the identity layer (which owns
|
|
107
|
+
* `--enable-features`/`--disable-features`) is not affected and the coherence checker does not
|
|
108
|
+
* flag them. */
|
|
109
|
+
export declare const FIRST_RUN_HYGIENE_ARGS: readonly ["--no-first-run", "--no-default-browser-check", "--disable-search-engine-choice-screen"];
|
|
110
|
+
/** True when `args` carries a positional (non-switch) argument, which Chromium opens as a URL.
|
|
111
|
+
* Everything after a literal `--` is positional by Chromium's command-line rules. */
|
|
112
|
+
export declare function hasUrlPositional(args: readonly string[]): boolean;
|
|
113
|
+
/** The neutral start page for a direct launch with no caller URL: `about:blank` as the final
|
|
114
|
+
* positional, so the first tab is blank instead of the ungoogled first-run page. Empty when the
|
|
115
|
+
* caller already supplied a URL positional (Chromium would open both otherwise). */
|
|
116
|
+
export declare function defaultStartUrlArgs(args: readonly string[]): string[];
|
|
117
|
+
/** Message thrown for a SOCKS proxy descriptor that carries `username`/`password`. Exported so the
|
|
118
|
+
* tests and the Python SDK's mirror can assert on the same wording. */
|
|
119
|
+
export declare const SOCKS_CREDENTIALS_UNSUPPORTED: string;
|
|
120
|
+
/** Resolve a Playwright proxy descriptor into `{ args, proxy }`.
|
|
121
|
+
*
|
|
122
|
+
* Every proxy shape is left to Playwright unchanged, except a SOCKS proxy WITH credentials, which
|
|
123
|
+
* throws: neither Playwright (it rejects credentials in a SOCKS descriptor) nor the engine (stock
|
|
124
|
+
* Chromium has no RFC 1929 client, and no ant0-browser patch adds one) can authenticate to it, so
|
|
125
|
+
* a launch would silently produce a proxy that refuses every connection. Callers needing a
|
|
126
|
+
* credentialed SOCKS5 upstream run a local relay and hand the SDK its unauthenticated loopback
|
|
127
|
+
* address instead. Userinfo inside the URL (`socks5://user:pass@host:port`) counts as credentials
|
|
128
|
+
* too: Chromium would drop it silently. */
|
|
129
|
+
export declare function resolveProxy(proxy: PwProxy | undefined): {
|
|
130
|
+
args: string[];
|
|
131
|
+
proxy: PwProxy | undefined;
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=launchopts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launchopts.d.ts","sourceRoot":"","sources":["../src/launchopts.ts"],"names":[],"mappings":"AAIA,qCAAqC;AACrC,MAAM,WAAW,OAAO;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;kFAWkF;AAClF,eAAO,MAAM,wBAAwB,yJAG3B,CAAC;AAEX;;;cAGc;AACd,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAa1D;AAED,sEAAsE;AACtE,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAE7C;AAED;;;oCAGoC;AACpC,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,EAAE,CAE7D;AAED;;;;;;;;;;;;;;;;;;mDAkBmD;AACnD,wBAAgB,aAAa,CAAC,SAAS,EAAE,OAAO,GAAG,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,M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