turno-browser 0.2.0 → 0.4.0
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/CHANGELOG.md +228 -0
- package/README.md +205 -16
- package/dist/act-model.d.ts +85 -0
- package/dist/act-model.js +116 -0
- package/dist/act.d.ts +37 -0
- package/dist/act.js +599 -0
- package/dist/api.d.ts +96 -0
- package/dist/api.js +88 -0
- package/dist/argv.d.ts +55 -3
- package/dist/argv.js +190 -10
- package/dist/batch.d.ts +19 -0
- package/dist/batch.js +148 -0
- package/dist/bench.d.ts +1 -1
- package/dist/bench.js +21 -5
- package/dist/bin/mcp.js +108 -12
- package/dist/captcha.d.ts +77 -0
- package/dist/captcha.js +333 -0
- package/dist/cdp-relay.d.ts +20 -0
- package/dist/cdp-relay.js +101 -0
- package/dist/chrome-features.d.ts +23 -0
- package/dist/chrome-features.js +44 -0
- package/dist/detectors.d.ts +11 -0
- package/dist/detectors.js +46 -4
- package/dist/diagnose.d.ts +45 -0
- package/dist/diagnose.js +326 -0
- package/dist/doctor.d.ts +85 -0
- package/dist/doctor.js +556 -0
- package/dist/engine-attach.d.ts +27 -0
- package/dist/engine-attach.js +165 -0
- package/dist/engine-camoufox.d.ts +32 -0
- package/dist/engine-camoufox.js +270 -0
- package/dist/engine-lightpanda.d.ts +72 -0
- package/dist/engine-lightpanda.js +292 -0
- package/dist/engine.d.ts +119 -0
- package/dist/engine.js +355 -0
- package/dist/flows.d.ts +127 -0
- package/dist/flows.js +294 -0
- package/dist/governor.d.ts +119 -0
- package/dist/governor.js +325 -0
- package/dist/health.d.ts +60 -0
- package/dist/health.js +86 -0
- package/dist/host.d.ts +95 -0
- package/dist/host.js +1181 -0
- package/dist/human-input.d.ts +84 -0
- package/dist/human-input.js +443 -0
- package/dist/humanize.d.ts +123 -0
- package/dist/humanize.js +241 -0
- package/dist/identities.d.ts +23 -10
- package/dist/identities.js +45 -37
- package/dist/idle-timer.d.ts +12 -0
- package/dist/idle-timer.js +25 -0
- package/dist/ids.d.ts +9 -0
- package/dist/ids.js +34 -0
- package/dist/index.d.ts +21 -6
- package/dist/index.js +19 -18
- package/dist/lifecycle.d.ts +99 -0
- package/dist/lifecycle.js +172 -0
- package/dist/live-client.d.ts +22 -0
- package/dist/live-client.js +93 -0
- package/dist/live-page.d.ts +11 -0
- package/dist/live-page.js +143 -0
- package/dist/live-server.d.ts +173 -0
- package/dist/live-server.js +640 -0
- package/dist/live.d.ts +120 -0
- package/dist/live.js +203 -0
- package/dist/login-tool.d.ts +45 -0
- package/dist/login-tool.js +233 -0
- package/dist/login.d.ts +8 -3
- package/dist/login.js +65 -26
- package/dist/network-chrome.d.ts +74 -0
- package/dist/network-chrome.js +178 -0
- package/dist/network.d.ts +125 -0
- package/dist/network.js +263 -0
- package/dist/opt-in-settings.d.ts +69 -0
- package/dist/opt-in-settings.js +151 -0
- package/dist/patchright.d.ts +4 -2
- package/dist/patchright.js +4 -2
- package/dist/recorder.d.ts +88 -0
- package/dist/recorder.js +538 -0
- package/dist/recordings.d.ts +116 -0
- package/dist/recordings.js +474 -0
- package/dist/redact.d.ts +34 -0
- package/dist/redact.js +135 -0
- package/dist/replay.d.ts +20 -0
- package/dist/replay.js +382 -0
- package/dist/reputation.d.ts +89 -0
- package/dist/reputation.js +203 -0
- package/dist/resources.d.ts +76 -0
- package/dist/resources.js +341 -0
- package/dist/runtime-lock.d.ts +59 -0
- package/dist/runtime-lock.js +131 -0
- package/dist/sealed.d.ts +8 -0
- package/dist/sealed.js +96 -0
- package/dist/session-export.d.ts +67 -0
- package/dist/session-export.js +194 -0
- package/dist/session.d.ts +20 -0
- package/dist/session.js +30 -0
- package/dist/settings.d.ts +246 -0
- package/dist/settings.js +530 -0
- package/dist/sharing.d.ts +96 -0
- package/dist/sharing.js +269 -0
- package/dist/snippet.d.ts +8 -0
- package/dist/snippet.js +22 -0
- package/dist/tab-locks.d.ts +63 -0
- package/dist/tab-locks.js +179 -0
- package/dist/tools.d.ts +111 -0
- package/dist/tools.js +59 -0
- package/dist/totp.d.ts +32 -0
- package/dist/totp.js +82 -0
- package/dist/tuning.d.ts +76 -0
- package/dist/tuning.js +69 -0
- package/dist/units.d.ts +8 -0
- package/dist/units.js +20 -0
- package/dist/upstream.d.ts +243 -0
- package/dist/upstream.js +46 -0
- package/dist/vault.d.ts +91 -0
- package/dist/vault.js +273 -0
- package/npm-shrinkwrap.json +1074 -3
- package/package.json +5 -4
- package/dist/paths.d.ts +0 -17
- package/dist/paths.js +0 -17
package/dist/sealed.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, randomBytes, scrypt as scryptCb } from "node:crypto";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
/**
|
|
4
|
+
* The encrypted envelope of a session export: a passphrase stretched with scrypt
|
|
5
|
+
* (random salt) into an AES-256-GCM key. The header (format, KDF parameters, cipher, IV) is the
|
|
6
|
+
* GCM additional data, so a changed header fails to decrypt like a changed ciphertext. The
|
|
7
|
+
* expiry lives inside the encrypted payload, where it cannot be edited without the passphrase.
|
|
8
|
+
*/
|
|
9
|
+
const scrypt = promisify(scryptCb);
|
|
10
|
+
export const SEALED_FORMAT = "turno-browser-session";
|
|
11
|
+
const VERSION = 1;
|
|
12
|
+
/** scrypt cost: 2^17 (about 128 MiB and a few hundred ms), the OWASP floor for scrypt. */
|
|
13
|
+
const KDF = { N: 2 ** 17, r: 8, p: 1 };
|
|
14
|
+
/** Ceiling on what a file may ask for, so a crafted header cannot make import allocate gigabytes. */
|
|
15
|
+
const MAX_N = 2 ** 20;
|
|
16
|
+
const MIN_PASSPHRASE = 12;
|
|
17
|
+
export class SealError extends Error {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "SealError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function aad(h) {
|
|
24
|
+
return Buffer.from(JSON.stringify({ format: h.format, version: h.version, kdf: h.kdf, cipher: h.cipher, iv: h.iv }));
|
|
25
|
+
}
|
|
26
|
+
async function key(passphrase, kdf) {
|
|
27
|
+
return await scrypt(passphrase.normalize("NFC"), Buffer.from(kdf.salt, "base64"), 32, {
|
|
28
|
+
N: kdf.N,
|
|
29
|
+
r: kdf.r,
|
|
30
|
+
p: kdf.p,
|
|
31
|
+
maxmem: 256 * kdf.N * kdf.r + 1024 * 1024,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** Encrypt `payload` (any JSON) under `passphrase`; the result is one JSON document. */
|
|
35
|
+
export async function seal(payload, passphrase) {
|
|
36
|
+
if (passphrase.length < MIN_PASSPHRASE)
|
|
37
|
+
throw new SealError(`the passphrase needs at least ${MIN_PASSPHRASE} characters`);
|
|
38
|
+
const header = {
|
|
39
|
+
format: SEALED_FORMAT,
|
|
40
|
+
version: VERSION,
|
|
41
|
+
kdf: { name: "scrypt", ...KDF, salt: randomBytes(16).toString("base64") },
|
|
42
|
+
cipher: "aes-256-gcm",
|
|
43
|
+
iv: randomBytes(12).toString("base64"),
|
|
44
|
+
};
|
|
45
|
+
const cipher = createCipheriv("aes-256-gcm", await key(passphrase, header.kdf), Buffer.from(header.iv, "base64"));
|
|
46
|
+
cipher.setAAD(aad(header));
|
|
47
|
+
const data = Buffer.concat([cipher.update(JSON.stringify(payload), "utf8"), cipher.final()]);
|
|
48
|
+
const envelope = { ...header, data: data.toString("base64"), tag: cipher.getAuthTag().toString("base64") };
|
|
49
|
+
return `${JSON.stringify(envelope)}\n`;
|
|
50
|
+
}
|
|
51
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
52
|
+
function parseEnvelope(text) {
|
|
53
|
+
let v;
|
|
54
|
+
try {
|
|
55
|
+
v = JSON.parse(text);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
throw new SealError("this is not a turno-browser session export");
|
|
59
|
+
}
|
|
60
|
+
if (!isObject(v) || v.format !== SEALED_FORMAT)
|
|
61
|
+
throw new SealError("this is not a turno-browser session export");
|
|
62
|
+
if (typeof v.version !== "number" || v.version > VERSION)
|
|
63
|
+
throw new SealError("this export is from a newer turno-browser; update turno-browser");
|
|
64
|
+
const kdf = v.kdf;
|
|
65
|
+
if (!isObject(kdf) ||
|
|
66
|
+
kdf.name !== "scrypt" ||
|
|
67
|
+
![kdf.N, kdf.r, kdf.p].every((n) => Number.isInteger(n) && n > 0) ||
|
|
68
|
+
kdf.N > MAX_N ||
|
|
69
|
+
(kdf.N & (kdf.N - 1)) !== 0 ||
|
|
70
|
+
kdf.r > 32 ||
|
|
71
|
+
kdf.p > 16 ||
|
|
72
|
+
typeof kdf.salt !== "string" ||
|
|
73
|
+
v.cipher !== "aes-256-gcm" ||
|
|
74
|
+
typeof v.iv !== "string" ||
|
|
75
|
+
typeof v.data !== "string" ||
|
|
76
|
+
typeof v.tag !== "string") {
|
|
77
|
+
throw new SealError("this session export is damaged (its header is not valid)");
|
|
78
|
+
}
|
|
79
|
+
return v;
|
|
80
|
+
}
|
|
81
|
+
/** Decrypt an export; a wrong passphrase and a changed file give the same error. */
|
|
82
|
+
export async function unseal(text, passphrase) {
|
|
83
|
+
const env = parseEnvelope(text);
|
|
84
|
+
const decipher = createDecipheriv("aes-256-gcm", await key(passphrase, env.kdf), Buffer.from(env.iv, "base64"));
|
|
85
|
+
decipher.setAAD(aad(env));
|
|
86
|
+
decipher.setAuthTag(Buffer.from(env.tag, "base64"));
|
|
87
|
+
let plain;
|
|
88
|
+
try {
|
|
89
|
+
plain = Buffer.concat([decipher.update(Buffer.from(env.data, "base64")), decipher.final()]);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
throw new SealError("wrong passphrase, or the file was changed");
|
|
93
|
+
}
|
|
94
|
+
return JSON.parse(plain.toString("utf8"));
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=sealed.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { BrowserContext } from "patchright-core";
|
|
2
|
+
/**
|
|
3
|
+
* Session export and import: an identity's cookies, localStorage and IndexedDB, as
|
|
4
|
+
* Playwright's storageState, sealed under a passphrase (sealed.ts) with an expiry inside the
|
|
5
|
+
* encrypted payload. For moving a signed-in identity to another machine or account, or keeping
|
|
6
|
+
* a short-lived backup. The vault is never part of it: its values live in the secret
|
|
7
|
+
* store, which the export does not read.
|
|
8
|
+
*/
|
|
9
|
+
type StorageState = Awaited<ReturnType<BrowserContext["storageState"]>>;
|
|
10
|
+
interface Payload {
|
|
11
|
+
kind: "turno-browser-session";
|
|
12
|
+
identity: string;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
expiresAt: string;
|
|
15
|
+
storageState: StorageState;
|
|
16
|
+
}
|
|
17
|
+
export interface ExportOptions {
|
|
18
|
+
passphrase: string;
|
|
19
|
+
/** How long the export can be imported, in milliseconds (default 7 days, at most 90). */
|
|
20
|
+
expiresInMs?: number;
|
|
21
|
+
env?: NodeJS.ProcessEnv;
|
|
22
|
+
now?: Date;
|
|
23
|
+
}
|
|
24
|
+
export interface SessionSummary {
|
|
25
|
+
identity: string;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
expiresAt: string;
|
|
28
|
+
cookies: number;
|
|
29
|
+
origins: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The origins that may hold site storage in a profile. Playwright's storageState reads
|
|
33
|
+
* localStorage and IndexedDB only for origins the context opened since it started, which for a
|
|
34
|
+
* profile just opened is none; these are what export opens first. They come from the IndexedDB
|
|
35
|
+
* folder names (`https_example.com_0.indexeddb.leveldb`), the origin keys in the Local Storage
|
|
36
|
+
* database (`META:https://example.com`), and the cookies' hosts.
|
|
37
|
+
*/
|
|
38
|
+
export declare function profileOrigins(profileDir: string, cookies: {
|
|
39
|
+
domain: string;
|
|
40
|
+
secure: boolean;
|
|
41
|
+
}[]): string[];
|
|
42
|
+
/** The sealed export of an identity's session, and what it holds (counts only). */
|
|
43
|
+
export declare function exportSession(id: string, options: ExportOptions): Promise<{
|
|
44
|
+
sealed: string;
|
|
45
|
+
summary: SessionSummary;
|
|
46
|
+
}>;
|
|
47
|
+
/** Decrypt and check an export without touching any identity: what `import --dry-run` shows. */
|
|
48
|
+
export declare function readSessionExport(text: string, passphrase: string, now?: Date): Promise<{
|
|
49
|
+
payload: Payload;
|
|
50
|
+
summary: SessionSummary;
|
|
51
|
+
}>;
|
|
52
|
+
export interface ImportOptions {
|
|
53
|
+
passphrase: string;
|
|
54
|
+
/** Import into this identity instead of the one the export came from. */
|
|
55
|
+
as?: string;
|
|
56
|
+
env?: NodeJS.ProcessEnv;
|
|
57
|
+
now?: Date;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Replace an identity's cookies, localStorage and IndexedDB with an export's (creating the
|
|
61
|
+
* identity when it does not exist). The caller confirms first when the identity exists: what
|
|
62
|
+
* it had is gone afterwards.
|
|
63
|
+
*/
|
|
64
|
+
export declare function importSession(text: string, options: ImportOptions): Promise<SessionSummary & {
|
|
65
|
+
created: boolean;
|
|
66
|
+
}>;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { clearHealth } from "./health.js";
|
|
4
|
+
import { IdentityError, addIdentity, assertIdentityId, identityDir, identityExists, inUseBy, isInUse, } from "./identities.js";
|
|
5
|
+
import { readLockPid } from "./lifecycle.js";
|
|
6
|
+
import { acquireRuntimeLock } from "./runtime-lock.js";
|
|
7
|
+
import { SealError, seal, unseal } from "./sealed.js";
|
|
8
|
+
import { chromeEnv, keychainArgs, launchSettings, readIdentitySettings, systemTimezone } from "./settings.js";
|
|
9
|
+
const DEFAULT_EXPIRY_MS = 7 * 24 * 3600_000;
|
|
10
|
+
const MAX_EXPIRY_MS = 90 * 24 * 3600_000;
|
|
11
|
+
/** Open the identity's profile headless, with its settings, hold its lock, and run `use`. */
|
|
12
|
+
async function withProfile(id, env, holder, use) {
|
|
13
|
+
const holderMessage = inUseBy(id, env);
|
|
14
|
+
if (holderMessage)
|
|
15
|
+
throw new IdentityError(holderMessage);
|
|
16
|
+
if (isInUse(id, env))
|
|
17
|
+
throw new IdentityError(`identity "${id}" is in use by a running Chrome; close it first`);
|
|
18
|
+
const settings = readIdentitySettings(id, env);
|
|
19
|
+
const held = acquireRuntimeLock(id, env, { holder });
|
|
20
|
+
try {
|
|
21
|
+
const dir = identityDir(id, env);
|
|
22
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
23
|
+
const applied = launchSettings(settings, [], systemTimezone());
|
|
24
|
+
const { chromium } = await import("patchright-core");
|
|
25
|
+
const ctx = await chromium.launchPersistentContext(dir, {
|
|
26
|
+
channel: "chrome",
|
|
27
|
+
headless: true,
|
|
28
|
+
viewport: null,
|
|
29
|
+
...(applied.args.length ? { args: applied.args } : {}),
|
|
30
|
+
...(applied.timezoneId ? { timezoneId: applied.timezoneId } : {}),
|
|
31
|
+
...keychainArgs(settings),
|
|
32
|
+
// Chrome gets the caller's environment (HOME, XDG dirs), not this process's.
|
|
33
|
+
env: chromeEnv(env),
|
|
34
|
+
});
|
|
35
|
+
const pid = readLockPid(dir);
|
|
36
|
+
if (pid !== undefined)
|
|
37
|
+
held.update({ chromePid: pid, pgid: pid });
|
|
38
|
+
try {
|
|
39
|
+
return await use(ctx);
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
await ctx.close().catch(() => undefined);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
held.release();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Most origins an export visits; a profile with more keeps only these (the first found). */
|
|
50
|
+
const MAX_ORIGINS = 2_000;
|
|
51
|
+
function originOf(text) {
|
|
52
|
+
try {
|
|
53
|
+
const u = new URL(text);
|
|
54
|
+
return u.protocol === "https:" || u.protocol === "http:" ? u.origin : undefined;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function listDir(dir) {
|
|
61
|
+
try {
|
|
62
|
+
return readdirSync(dir);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The origins that may hold site storage in a profile. Playwright's storageState reads
|
|
70
|
+
* localStorage and IndexedDB only for origins the context opened since it started, which for a
|
|
71
|
+
* profile just opened is none; these are what export opens first. They come from the IndexedDB
|
|
72
|
+
* folder names (`https_example.com_0.indexeddb.leveldb`), the origin keys in the Local Storage
|
|
73
|
+
* database (`META:https://example.com`), and the cookies' hosts.
|
|
74
|
+
*/
|
|
75
|
+
export function profileOrigins(profileDir, cookies) {
|
|
76
|
+
const found = new Set();
|
|
77
|
+
const add = (o) => {
|
|
78
|
+
if (o && found.size < MAX_ORIGINS)
|
|
79
|
+
found.add(o);
|
|
80
|
+
};
|
|
81
|
+
const base = join(profileDir, "Default");
|
|
82
|
+
for (const name of listDir(join(base, "IndexedDB"))) {
|
|
83
|
+
const m = /^(https?)_(.+)_(\d+)\.indexeddb\.(leveldb|blob)$/.exec(name);
|
|
84
|
+
if (m)
|
|
85
|
+
add(originOf(`${m[1]}://${m[2]}${m[3] === "0" ? "" : `:${m[3]}`}`));
|
|
86
|
+
}
|
|
87
|
+
const leveldb = join(base, "Local Storage", "leveldb");
|
|
88
|
+
for (const name of listDir(leveldb)) {
|
|
89
|
+
if (!/\.(log|ldb)$/.test(name))
|
|
90
|
+
continue;
|
|
91
|
+
let text;
|
|
92
|
+
try {
|
|
93
|
+
text = readFileSync(join(leveldb, name), "latin1");
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
for (const m of text.matchAll(/(?:META:|_)(https?:\/\/[a-z0-9.-]+(?::\d{1,5})?|https?:\/\/\[[0-9a-f:]+\](?::\d{1,5})?)/gi))
|
|
99
|
+
add(originOf(m[1]));
|
|
100
|
+
}
|
|
101
|
+
for (const c of cookies) {
|
|
102
|
+
const host = c.domain.replace(/^\./, "");
|
|
103
|
+
add(originOf(`https://${host}`));
|
|
104
|
+
if (!c.secure)
|
|
105
|
+
add(originOf(`http://${host}`));
|
|
106
|
+
}
|
|
107
|
+
return [...found];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Open each origin in one page whose requests are all answered locally with an empty
|
|
111
|
+
* document, so the context knows them and storageState reads their storage. Nothing goes to
|
|
112
|
+
* the network.
|
|
113
|
+
*/
|
|
114
|
+
async function visitOrigins(ctx, origins) {
|
|
115
|
+
if (!origins.length)
|
|
116
|
+
return;
|
|
117
|
+
const page = await ctx.newPage();
|
|
118
|
+
try {
|
|
119
|
+
await page.route("**/*", (route) => route.fulfill({ status: 200, contentType: "text/html", body: "<!doctype html><title></title>" }));
|
|
120
|
+
for (const origin of origins)
|
|
121
|
+
await page.goto(`${origin}/`, { waitUntil: "commit", timeout: 10_000 }).catch(() => undefined);
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
await page.close().catch(() => undefined);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function summary(p) {
|
|
128
|
+
return {
|
|
129
|
+
identity: p.identity,
|
|
130
|
+
createdAt: p.createdAt,
|
|
131
|
+
expiresAt: p.expiresAt,
|
|
132
|
+
cookies: p.storageState.cookies.length,
|
|
133
|
+
origins: p.storageState.origins.length,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** The sealed export of an identity's session, and what it holds (counts only). */
|
|
137
|
+
export async function exportSession(id, options) {
|
|
138
|
+
const env = options.env ?? process.env;
|
|
139
|
+
assertIdentityId(id);
|
|
140
|
+
if (!identityExists(id, env))
|
|
141
|
+
throw new IdentityError(`identity "${id}" does not exist`);
|
|
142
|
+
const expiresIn = options.expiresInMs ?? DEFAULT_EXPIRY_MS;
|
|
143
|
+
if (!(expiresIn > 0 && expiresIn <= MAX_EXPIRY_MS))
|
|
144
|
+
throw new SealError("the expiry must be more than 0 and at most 90 days");
|
|
145
|
+
const storageState = await withProfile(id, env, "export", async (ctx) => {
|
|
146
|
+
await visitOrigins(ctx, profileOrigins(identityDir(id, env), await ctx.cookies()));
|
|
147
|
+
return await ctx.storageState({ indexedDB: true });
|
|
148
|
+
});
|
|
149
|
+
const now = options.now ?? new Date();
|
|
150
|
+
const payload = {
|
|
151
|
+
kind: "turno-browser-session",
|
|
152
|
+
identity: id,
|
|
153
|
+
createdAt: now.toISOString(),
|
|
154
|
+
expiresAt: new Date(now.getTime() + expiresIn).toISOString(),
|
|
155
|
+
storageState,
|
|
156
|
+
};
|
|
157
|
+
return { sealed: await seal(payload, options.passphrase), summary: summary(payload) };
|
|
158
|
+
}
|
|
159
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
160
|
+
function isPayload(v) {
|
|
161
|
+
if (!isObject(v) || v.kind !== "turno-browser-session" || typeof v.identity !== "string")
|
|
162
|
+
return false;
|
|
163
|
+
if (typeof v.createdAt !== "string" || typeof v.expiresAt !== "string" || Number.isNaN(Date.parse(v.expiresAt)))
|
|
164
|
+
return false;
|
|
165
|
+
const s = v.storageState;
|
|
166
|
+
return isObject(s) && Array.isArray(s.cookies) && Array.isArray(s.origins);
|
|
167
|
+
}
|
|
168
|
+
/** Decrypt and check an export without touching any identity: what `import --dry-run` shows. */
|
|
169
|
+
export async function readSessionExport(text, passphrase, now = new Date()) {
|
|
170
|
+
const v = await unseal(text, passphrase);
|
|
171
|
+
if (!isPayload(v))
|
|
172
|
+
throw new SealError("this session export is damaged (its content is not a session)");
|
|
173
|
+
if (now.getTime() > Date.parse(v.expiresAt))
|
|
174
|
+
throw new SealError(`this session export expired on ${v.expiresAt}; export it again`);
|
|
175
|
+
return { payload: v, summary: summary(v) };
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Replace an identity's cookies, localStorage and IndexedDB with an export's (creating the
|
|
179
|
+
* identity when it does not exist). The caller confirms first when the identity exists: what
|
|
180
|
+
* it had is gone afterwards.
|
|
181
|
+
*/
|
|
182
|
+
export async function importSession(text, options) {
|
|
183
|
+
const env = options.env ?? process.env;
|
|
184
|
+
const { payload, summary: s } = await readSessionExport(text, options.passphrase, options.now);
|
|
185
|
+
const id = options.as ?? payload.identity;
|
|
186
|
+
assertIdentityId(id);
|
|
187
|
+
const created = !identityExists(id, env);
|
|
188
|
+
if (created)
|
|
189
|
+
addIdentity(id, env);
|
|
190
|
+
await withProfile(id, env, "import", (ctx) => ctx.setStorageState(payload.storageState));
|
|
191
|
+
clearHealth(id, env);
|
|
192
|
+
return { ...s, identity: id, created };
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=session-export.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client session mcpd relays a call for. mcpd puts an opaque id, stable for one
|
|
3
|
+
* client session and different for every other, in the `_meta` of each `tools/call` it
|
|
4
|
+
* forwards, under this key. The host hands it to turno tools, and with `"sharing": "tabs"`
|
|
5
|
+
* keys each session's backend and tab locks on it (`sharing.ts`).
|
|
6
|
+
*/
|
|
7
|
+
export declare const SESSION_META_KEY = "io.turno/session";
|
|
8
|
+
/**
|
|
9
|
+
* The experimental capability a server declares in `initialize` to hear when a client session
|
|
10
|
+
* ends: mcpd then sends it `SESSION_ENDED_METHOD` with `{ session: <the id above> }` for each
|
|
11
|
+
* session that made a call and went away. A server without it never gets the notification.
|
|
12
|
+
*/
|
|
13
|
+
export declare const SESSION_CAPABILITY = "io.turno/sessions";
|
|
14
|
+
/** The notification mcpd sends when a client session ends (see `SESSION_CAPABILITY`). */
|
|
15
|
+
export declare const SESSION_ENDED_METHOD = "notifications/io.turno/session_ended";
|
|
16
|
+
/**
|
|
17
|
+
* The session id in a request's `_meta`, or undefined when there is none or it is not a short
|
|
18
|
+
* printable string (a client talking to the server directly may send anything there).
|
|
19
|
+
*/
|
|
20
|
+
export declare function sessionFromMeta(meta: unknown): string | undefined;
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client session mcpd relays a call for. mcpd puts an opaque id, stable for one
|
|
3
|
+
* client session and different for every other, in the `_meta` of each `tools/call` it
|
|
4
|
+
* forwards, under this key. The host hands it to turno tools, and with `"sharing": "tabs"`
|
|
5
|
+
* keys each session's backend and tab locks on it (`sharing.ts`).
|
|
6
|
+
*/
|
|
7
|
+
export const SESSION_META_KEY = "io.turno/session";
|
|
8
|
+
/**
|
|
9
|
+
* The experimental capability a server declares in `initialize` to hear when a client session
|
|
10
|
+
* ends: mcpd then sends it `SESSION_ENDED_METHOD` with `{ session: <the id above> }` for each
|
|
11
|
+
* session that made a call and went away. A server without it never gets the notification.
|
|
12
|
+
*/
|
|
13
|
+
export const SESSION_CAPABILITY = "io.turno/sessions";
|
|
14
|
+
/** The notification mcpd sends when a client session ends (see `SESSION_CAPABILITY`). */
|
|
15
|
+
export const SESSION_ENDED_METHOD = "notifications/io.turno/session_ended";
|
|
16
|
+
/** Longest session id accepted; mcpd sends a UUID. */
|
|
17
|
+
const MAX_SESSION = 128;
|
|
18
|
+
/**
|
|
19
|
+
* The session id in a request's `_meta`, or undefined when there is none or it is not a short
|
|
20
|
+
* printable string (a client talking to the server directly may send anything there).
|
|
21
|
+
*/
|
|
22
|
+
export function sessionFromMeta(meta) {
|
|
23
|
+
if (typeof meta !== "object" || meta === null)
|
|
24
|
+
return undefined;
|
|
25
|
+
const value = meta[SESSION_META_KEY];
|
|
26
|
+
if (typeof value !== "string" || value.length === 0 || value.length > MAX_SESSION)
|
|
27
|
+
return undefined;
|
|
28
|
+
return /^[\x21-\x7e]+$/.test(value) ? value : undefined;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { type ActSettings, type CaptchaSettings } from "./opt-in-settings.js";
|
|
2
|
+
import { type HumanizeSettings } from "./humanize.js";
|
|
3
|
+
import { type ProxySettings, type UserAgentMode } from "./network.js";
|
|
4
|
+
/**
|
|
5
|
+
* identity.json: what stays fixed for one browser identity, so a site sees the same person in
|
|
6
|
+
* the same place every time. It sits next to the Chrome profile directory
|
|
7
|
+
* (`<data>/browser/identities/<id>.json`), never inside it, so Chrome never reads or rewrites it
|
|
8
|
+
* and copying a profile does not copy it by accident.
|
|
9
|
+
*
|
|
10
|
+
* - `timezone`: an IANA zone. Chrome gets it as `timezoneId`, only when it differs from the
|
|
11
|
+
* system's (an identity set up at home keeps that zone on a trip).
|
|
12
|
+
* - `languages`: the Accept-Language order, passed as Chrome's own `--accept-lang`, so the
|
|
13
|
+
* header keeps Chrome's q-values and `navigator.languages` matches it. Without it, `locale`
|
|
14
|
+
* gives `[locale, base language]`.
|
|
15
|
+
* - `locale`: also passed as `--lang` (Chrome's UI and, on Linux and Windows, `Intl`). It is not
|
|
16
|
+
* Playwright's `locale` option: that one collapses Accept-Language to a single value, which no
|
|
17
|
+
* installed Chrome sends (measured with Chrome 157).
|
|
18
|
+
* - `region`: the two-letter country the identity's sites know it from. Recorded, not applied.
|
|
19
|
+
* - `health`: a URL and a text or selector that proves the identity is signed in (session
|
|
20
|
+
* health, `health.ts`).
|
|
21
|
+
* - `tabs`, `backgroundThrottling`, `settle`, `block`, `cache` (format 2): how the host runs this
|
|
22
|
+
* identity's Chrome
|
|
23
|
+
* (`tuning.ts`): the tab governor and background tab throttling.
|
|
24
|
+
* - `keychain` (format 3): where Chrome gets the key that encrypts the profile's cookies.
|
|
25
|
+
* `"mock"` (the default, also when the key is missing) keeps Playwright's
|
|
26
|
+
* `--use-mock-keychain` and `--password-store=basic`, a fixed public key; `"system"` drops
|
|
27
|
+
* them, so Chrome uses the macOS Keychain or the Linux Secret Service.
|
|
28
|
+
* - `humanize` (format 4): human-like pointer, typing and scrolling (`humanize.ts`), off by default.
|
|
29
|
+
* - `sharing` (format 5): `"session"` (the default) serves one agent session at a time;
|
|
30
|
+
* `"tabs"` lets several sessions use the browser at once, each in its own locked tabs
|
|
31
|
+
* (`sharing.ts`; mcp.toml then runs the server with `exclusive = false`).
|
|
32
|
+
* - `engine`, `attach` (format 6): which engine runs the identity (`engine.ts`). `engine:
|
|
33
|
+
* "lightpanda"` is read mode; `attach` connects to a Chrome the user already has open
|
|
34
|
+
* (`"auto"`, a user data dir, or a loopback endpoint). Both off by default.
|
|
35
|
+
* - `record` (format 7): what turno-browser records for this identity, all off by default:
|
|
36
|
+
* `flows` (every session's actions as a flow, `recorder.ts`), `traces` (Playwright traces) and
|
|
37
|
+
* `screenshots` (one per action), the last two under the identity's state folder with a
|
|
38
|
+
* size cap (`maxSize`, default 200MB) and the oldest recordings removed first (`recordings.ts`).
|
|
39
|
+
* - `act`, `captcha` (format 8): natural language actions and captcha solving, both off by
|
|
40
|
+
* default and both sending page content to a model or a solver the user picks
|
|
41
|
+
* (`opt-in-settings.ts`). Keys are `keychain:` references, never values.
|
|
42
|
+
* - `tabLocks` (format 9): with `"sharing": "tabs"`, how long a call waits for a tab another
|
|
43
|
+
* session holds (`wait`, default 10s) and how long a session without calls keeps its tabs
|
|
44
|
+
* (`release`, default 5m) (`tab-locks.ts`). No effect with `"sharing": "session"`.
|
|
45
|
+
* - `live` (format 10): the live view and take-over (`live.ts`), off by default: `enabled` serves
|
|
46
|
+
* a view of the agent's tab on 127.0.0.1 and lets the user pause the agent; `wait` is how long
|
|
47
|
+
* a paused call waits for the user to resume before it fails (default 2m).
|
|
48
|
+
* - `userAgent`, `proxy` (format 11), and the `"camoufox"` value of `engine`: opt-in network and
|
|
49
|
+
* user agent settings (`network.ts`) and Camoufox as an alternate engine
|
|
50
|
+
* (`engine-camoufox.ts`), all off by default.
|
|
51
|
+
*
|
|
52
|
+
* A missing file means Chrome's own defaults, as before identity.json existed.
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* The newest format version of identity.json this package reads, in its `version` key: turno's
|
|
56
|
+
* state-file convention, where a file without `version` is format 1 and a newer one
|
|
57
|
+
* is refused. Format 2 adds the browser keys (`FORMAT_2_KEYS`); a file is written as format 2
|
|
58
|
+
* only when it uses one of them, so an older turno-browser keeps reading every other file and
|
|
59
|
+
* refuses one it would misread with "update turno-browser".
|
|
60
|
+
*/
|
|
61
|
+
export declare const IDENTITY_FORMAT_VERSION = 11;
|
|
62
|
+
/** The keys format 2 added. */
|
|
63
|
+
declare const FORMAT_2_KEYS: readonly ["tabs", "backgroundThrottling", "settle", "block", "cache"];
|
|
64
|
+
/** The keys format 3 added. */
|
|
65
|
+
declare const FORMAT_3_KEYS: readonly ["keychain"];
|
|
66
|
+
/** The keys format 4 added. */
|
|
67
|
+
declare const FORMAT_4_KEYS: readonly ["humanize"];
|
|
68
|
+
/** The keys format 5 added. */
|
|
69
|
+
declare const FORMAT_5_KEYS: readonly ["sharing"];
|
|
70
|
+
/** The keys format 6 added. */
|
|
71
|
+
declare const FORMAT_6_KEYS: readonly ["engine", "attach"];
|
|
72
|
+
/** The keys format 7 added. */
|
|
73
|
+
declare const FORMAT_7_KEYS: readonly ["record"];
|
|
74
|
+
/** The keys format 8 added. */
|
|
75
|
+
declare const FORMAT_8_KEYS: readonly ["act", "captcha"];
|
|
76
|
+
/** The keys format 9 added. */
|
|
77
|
+
declare const FORMAT_9_KEYS: readonly ["tabLocks"];
|
|
78
|
+
/** With `"sharing": "tabs"`: the lock wait and the idle release, as durations. */
|
|
79
|
+
export interface TabLockSettings {
|
|
80
|
+
wait?: string;
|
|
81
|
+
release?: string;
|
|
82
|
+
}
|
|
83
|
+
/** The keys format 10 added. */
|
|
84
|
+
declare const FORMAT_10_KEYS: readonly ["live"];
|
|
85
|
+
/** The live view and take-over (`live.ts`); off by default. */
|
|
86
|
+
export interface LiveSettings {
|
|
87
|
+
/** Serve the live view and let the user pause the agent. */
|
|
88
|
+
enabled?: boolean;
|
|
89
|
+
/** How long a paused call waits for the user, like `"2m"` (from `"5s"` to `"30m"`). */
|
|
90
|
+
wait?: string;
|
|
91
|
+
}
|
|
92
|
+
/** Bounds of `live.wait`. */
|
|
93
|
+
export declare const MIN_LIVE_WAIT_MS = 5000;
|
|
94
|
+
export declare const MAX_LIVE_WAIT_MS: number;
|
|
95
|
+
/** The keys format 11 added (the `"camoufox"` engine also writes format 11). */
|
|
96
|
+
declare const FORMAT_11_KEYS: readonly ["userAgent", "proxy"];
|
|
97
|
+
/** The values of `engine`: `"chrome"` (the default), read mode, and Camoufox (format 11). */
|
|
98
|
+
declare const ENGINE_VALUES: readonly ["chrome", "lightpanda", "camoufox"];
|
|
99
|
+
/** What turno-browser records for an identity (`recorder.ts`, `recordings.ts`); all off by default. */
|
|
100
|
+
export interface RecordSettings {
|
|
101
|
+
/** Record every session's actions as a flow (`auto-<time>`), the newest few kept. */
|
|
102
|
+
flows?: boolean;
|
|
103
|
+
/** Playwright traces of each browser session, paused around vault sign-ins. */
|
|
104
|
+
traces?: boolean;
|
|
105
|
+
/** A screenshot after each action, skipped on a page that holds vault values. */
|
|
106
|
+
screenshots?: boolean;
|
|
107
|
+
/** Size cap of the identity's recordings, like `"200MB"`; the oldest go first. */
|
|
108
|
+
maxSize?: string;
|
|
109
|
+
}
|
|
110
|
+
/** How many agent sessions use the identity's browser at once (`sharing.ts`). */
|
|
111
|
+
type SharingSetting = "session" | "tabs";
|
|
112
|
+
/** Where Chrome gets its cookie encryption key. */
|
|
113
|
+
type KeychainMode = "mock" | "system";
|
|
114
|
+
/** Resource types `block.types` may name: the heavy ones a page usually works without. */
|
|
115
|
+
declare const BLOCKABLE_TYPES: readonly ["image", "media", "font"];
|
|
116
|
+
type BlockableType = (typeof BLOCKABLE_TYPES)[number];
|
|
117
|
+
/** Opt-in resource blocking (`resources.ts`). */
|
|
118
|
+
interface BlockSettings {
|
|
119
|
+
/** The built-in list of ad and tracker hosts. */
|
|
120
|
+
trackers?: boolean;
|
|
121
|
+
types?: BlockableType[];
|
|
122
|
+
/** Host names (with their subdomains) or URL globs (`*` matches anything). */
|
|
123
|
+
patterns?: string[];
|
|
124
|
+
}
|
|
125
|
+
/** Opt-in on-disk resource cache (`resources.ts`). */
|
|
126
|
+
interface CacheSettings {
|
|
127
|
+
/** Size cap, like `"100MB"` (default 100MB). */
|
|
128
|
+
maxSize?: string;
|
|
129
|
+
}
|
|
130
|
+
/** The tab governor (`tuning.ts`): durations are strings like `"5m"`, `"0"` turns a stage off. */
|
|
131
|
+
interface TabSettings {
|
|
132
|
+
/** Most pages open at once; the least recently used one closes past it. 0: no cap. */
|
|
133
|
+
max?: number;
|
|
134
|
+
/** `"close"`: close a popup the agent did not open; `"keep"`: leave it. */
|
|
135
|
+
popups?: "close" | "keep";
|
|
136
|
+
/** Unused this long, a page is parked on about:blank (its URL comes back on the next use). */
|
|
137
|
+
park?: string;
|
|
138
|
+
/** Unused this long, a page is closed. */
|
|
139
|
+
close?: string;
|
|
140
|
+
}
|
|
141
|
+
export interface HealthCheck {
|
|
142
|
+
/** A page that shows `text` or `selector` only to a signed-in user. */
|
|
143
|
+
url: string;
|
|
144
|
+
text?: string;
|
|
145
|
+
selector?: string;
|
|
146
|
+
}
|
|
147
|
+
export interface IdentitySettings {
|
|
148
|
+
/** Format version (`IDENTITY_FORMAT_VERSION`); a file without it is format 1. */
|
|
149
|
+
version?: number;
|
|
150
|
+
timezone?: string;
|
|
151
|
+
locale?: string;
|
|
152
|
+
languages?: string[];
|
|
153
|
+
region?: string;
|
|
154
|
+
health?: HealthCheck;
|
|
155
|
+
tabs?: TabSettings;
|
|
156
|
+
/** True: let Chrome throttle tabs that are not in front (see `tuning.ts`). */
|
|
157
|
+
backgroundThrottling?: boolean;
|
|
158
|
+
/** Wait after each action for the work it started, like `"250ms"` (Playwright's `timeouts.settle`). */
|
|
159
|
+
settle?: string;
|
|
160
|
+
block?: BlockSettings;
|
|
161
|
+
cache?: CacheSettings;
|
|
162
|
+
/** `"system"`: Chrome encrypts cookies with the OS store's key; default `"mock"`. */
|
|
163
|
+
keychain?: KeychainMode;
|
|
164
|
+
/** Human-like input: `level` (off, light, full, adaptive) and an optional `seed`. */
|
|
165
|
+
humanize?: HumanizeSettings;
|
|
166
|
+
/** `"tabs"`: several agent sessions at once, each in its own locked tabs; default `"session"`. */
|
|
167
|
+
sharing?: SharingSetting;
|
|
168
|
+
/** `"lightpanda"`: read mode on Lightpanda; `"camoufox"`: Camoufox; default `"chrome"`. */
|
|
169
|
+
engine?: (typeof ENGINE_VALUES)[number];
|
|
170
|
+
/** Connect to a Chrome the user has open: `"auto"`, a user data dir, or a loopback endpoint. */
|
|
171
|
+
attach?: string;
|
|
172
|
+
record?: RecordSettings;
|
|
173
|
+
/** Natural language actions (`browser_act`, `browser_extract`, `browser_observe`); off by default. */
|
|
174
|
+
act?: ActSettings;
|
|
175
|
+
/** A captcha solver for `browser_solve_captcha`; off by default. */
|
|
176
|
+
captcha?: CaptchaSettings;
|
|
177
|
+
/** With `"sharing": "tabs"`: how long a call waits for a held tab, and when an idle session lets go. */
|
|
178
|
+
tabLocks?: TabLockSettings;
|
|
179
|
+
/** The live view and take-over: `enabled` and `wait`; off by default. */
|
|
180
|
+
live?: LiveSettings;
|
|
181
|
+
/** `"coherent"`: the installed Chrome's own user agent and client hints, checked at launch. */
|
|
182
|
+
userAgent?: UserAgentMode;
|
|
183
|
+
/** A proxy for the identity's traffic; credentials only as `keychain:` references. */
|
|
184
|
+
proxy?: ProxySettings;
|
|
185
|
+
/** ISO dates. */
|
|
186
|
+
created: string;
|
|
187
|
+
updated: string;
|
|
188
|
+
}
|
|
189
|
+
/** A change to identity.json: a value sets the key, `null` removes it. */
|
|
190
|
+
export type SettingsPatch = {
|
|
191
|
+
[K in "timezone" | "locale" | "languages" | "region" | "health" | (typeof FORMAT_2_KEYS)[number] | (typeof FORMAT_3_KEYS)[number] | (typeof FORMAT_4_KEYS)[number] | (typeof FORMAT_5_KEYS)[number] | (typeof FORMAT_6_KEYS)[number] | (typeof FORMAT_7_KEYS)[number] | (typeof FORMAT_8_KEYS)[number] | (typeof FORMAT_9_KEYS)[number] | (typeof FORMAT_10_KEYS)[number] | (typeof FORMAT_11_KEYS)[number]]?: IdentitySettings[K] | null;
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* The Chrome switches to drop for this identity's keychain setting, as Playwright launch
|
|
195
|
+
* options: nothing for the default mock keychain.
|
|
196
|
+
*/
|
|
197
|
+
export declare function keychainArgs(settings: Pick<IdentitySettings, "keychain"> | undefined): {
|
|
198
|
+
ignoreDefaultArgs?: string[];
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* The environment for a Chrome this process launches for an identity: the caller's, so HOME
|
|
202
|
+
* and the XDG folders follow the identity's environment instead of this process's.
|
|
203
|
+
*/
|
|
204
|
+
export declare function chromeEnv(env: NodeJS.ProcessEnv): Record<string, string>;
|
|
205
|
+
/**
|
|
206
|
+
* Why an engine cannot record what `record` asks for. Attach mode: a trace covers every tab of
|
|
207
|
+
* the browser, the user's own too, so neither traces nor screenshots are taken there. Read mode:
|
|
208
|
+
* Lightpanda renders no page, so there is nothing to screenshot or screencast.
|
|
209
|
+
*/
|
|
210
|
+
export declare function recordEngineClash(engine: string, record: {
|
|
211
|
+
traces?: unknown;
|
|
212
|
+
screenshots?: unknown;
|
|
213
|
+
}): string | undefined;
|
|
214
|
+
export declare function identitySettingsPath(id: string, env?: NodeJS.ProcessEnv): string;
|
|
215
|
+
/** The system's IANA time zone, as Chrome reports it when nothing overrides it. */
|
|
216
|
+
export declare function systemTimezone(): string;
|
|
217
|
+
export interface SettingsCheck {
|
|
218
|
+
path: string;
|
|
219
|
+
/** Present when the file exists and is valid. */
|
|
220
|
+
settings?: IdentitySettings;
|
|
221
|
+
/** Why the file cannot be used; empty when it is valid or missing. */
|
|
222
|
+
problems: string[];
|
|
223
|
+
}
|
|
224
|
+
/** Reads identity.json without throwing: for `turno browser doctor`. */
|
|
225
|
+
export declare function checkIdentitySettings(id: string, env?: NodeJS.ProcessEnv): SettingsCheck;
|
|
226
|
+
/** identity.json of the identity, undefined when there is none. Throws when it is invalid. */
|
|
227
|
+
export declare function readIdentitySettings(id: string, env?: NodeJS.ProcessEnv): IdentitySettings | undefined;
|
|
228
|
+
/**
|
|
229
|
+
* Applies a patch and writes the file (mode 600, through a rename so a reader never sees half
|
|
230
|
+
* a file). Validates first: a bad value throws and leaves the file as it was.
|
|
231
|
+
*/
|
|
232
|
+
export declare function writeIdentitySettings(id: string, patch: SettingsPatch, env?: NodeJS.ProcessEnv, now?: Date): IdentitySettings;
|
|
233
|
+
/** The Accept-Language order: `languages`, else the locale and its base language. */
|
|
234
|
+
export declare function acceptLanguages(settings: IdentitySettings): string[] | undefined;
|
|
235
|
+
export interface LaunchSettings {
|
|
236
|
+
/** Chrome flags to add. */
|
|
237
|
+
args: string[];
|
|
238
|
+
/** Playwright's `timezoneId`, when the identity's zone is not the system's. */
|
|
239
|
+
timezoneId?: string;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* What the chrome engine adds at launch for these settings. Flags and context options the user
|
|
243
|
+
* already set (through `--config` or the Playwright MCP flags) always win.
|
|
244
|
+
*/
|
|
245
|
+
export declare function launchSettings(settings: IdentitySettings | undefined, userArgs: readonly string[], systemTz: string, userContext?: Record<string, unknown>): LaunchSettings;
|
|
246
|
+
export {};
|