turno-browser 0.3.0 → 0.5.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.
Files changed (131) hide show
  1. package/CHANGELOG.md +122 -0
  2. package/README.md +95 -123
  3. package/dist/act-model.d.ts +85 -0
  4. package/dist/act-model.js +117 -0
  5. package/dist/act.d.ts +37 -0
  6. package/dist/act.js +600 -0
  7. package/dist/api.d.ts +90 -2
  8. package/dist/api.js +41 -4
  9. package/dist/argv.d.ts +16 -2
  10. package/dist/argv.js +100 -3
  11. package/dist/background-state.d.ts +54 -0
  12. package/dist/background-state.js +97 -0
  13. package/dist/background.d.ts +69 -0
  14. package/dist/background.js +458 -0
  15. package/dist/batch.d.ts +5 -0
  16. package/dist/batch.js +3 -3
  17. package/dist/bin/mcp.js +103 -6
  18. package/dist/captcha.d.ts +77 -0
  19. package/dist/captcha.js +334 -0
  20. package/dist/cdp-relay.d.ts +20 -0
  21. package/dist/cdp-relay.js +101 -0
  22. package/dist/chrome-features.d.ts +23 -0
  23. package/dist/chrome-features.js +44 -0
  24. package/dist/cli/background.d.ts +11 -0
  25. package/dist/cli/background.js +132 -0
  26. package/dist/cli/commands.d.ts +16 -0
  27. package/dist/cli/commands.js +515 -0
  28. package/dist/cli/context.d.ts +75 -0
  29. package/dist/cli/context.js +44 -0
  30. package/dist/cli/do-background.d.ts +27 -0
  31. package/dist/cli/do-background.js +212 -0
  32. package/dist/cli/do.d.ts +85 -0
  33. package/dist/cli/do.js +558 -0
  34. package/dist/cli/flows.d.ts +28 -0
  35. package/dist/cli/flows.js +303 -0
  36. package/dist/cli/identity.d.ts +37 -0
  37. package/dist/cli/identity.js +906 -0
  38. package/dist/cli/live.d.ts +7 -0
  39. package/dist/cli/live.js +99 -0
  40. package/dist/cli/main.d.ts +16 -0
  41. package/dist/cli/main.js +171 -0
  42. package/dist/cli/secret.d.ts +4 -0
  43. package/dist/cli/secret.js +151 -0
  44. package/dist/cli/session.d.ts +6 -0
  45. package/dist/cli/session.js +106 -0
  46. package/dist/cli/setup.d.ts +7 -0
  47. package/dist/cli/setup.js +180 -0
  48. package/dist/cli/vault.d.ts +5 -0
  49. package/dist/cli/vault.js +192 -0
  50. package/dist/client.d.ts +82 -0
  51. package/dist/client.js +303 -0
  52. package/dist/diagnose.d.ts +7 -0
  53. package/dist/diagnose.js +61 -6
  54. package/dist/doctor.d.ts +37 -3
  55. package/dist/doctor.js +264 -6
  56. package/dist/engine-attach.d.ts +27 -0
  57. package/dist/engine-attach.js +165 -0
  58. package/dist/engine-camoufox.d.ts +32 -0
  59. package/dist/engine-camoufox.js +271 -0
  60. package/dist/engine-lightpanda.d.ts +72 -0
  61. package/dist/engine-lightpanda.js +293 -0
  62. package/dist/engine.d.ts +63 -11
  63. package/dist/engine.js +106 -29
  64. package/dist/flows.d.ts +127 -0
  65. package/dist/flows.js +294 -0
  66. package/dist/governor.d.ts +42 -7
  67. package/dist/governor.js +82 -32
  68. package/dist/health.js +2 -1
  69. package/dist/host.d.ts +38 -2
  70. package/dist/host.js +689 -52
  71. package/dist/human-input.d.ts +84 -0
  72. package/dist/human-input.js +448 -0
  73. package/dist/humanize.d.ts +123 -0
  74. package/dist/humanize.js +241 -0
  75. package/dist/identities.js +4 -1
  76. package/dist/idle-timer.d.ts +12 -0
  77. package/dist/idle-timer.js +25 -0
  78. package/dist/index.d.ts +13 -4
  79. package/dist/index.js +7 -1
  80. package/dist/lifecycle.d.ts +11 -1
  81. package/dist/lifecycle.js +11 -2
  82. package/dist/live-client.d.ts +22 -0
  83. package/dist/live-client.js +95 -0
  84. package/dist/live-page.d.ts +4 -0
  85. package/dist/live-page.js +144 -0
  86. package/dist/live-server.d.ts +173 -0
  87. package/dist/live-server.js +643 -0
  88. package/dist/live.d.ts +120 -0
  89. package/dist/live.js +204 -0
  90. package/dist/login-tool.d.ts +13 -0
  91. package/dist/login-tool.js +8 -3
  92. package/dist/login.d.ts +4 -1
  93. package/dist/login.js +12 -2
  94. package/dist/names.d.ts +28 -0
  95. package/dist/names.js +25 -0
  96. package/dist/network-chrome.d.ts +74 -0
  97. package/dist/network-chrome.js +178 -0
  98. package/dist/network.d.ts +125 -0
  99. package/dist/network.js +264 -0
  100. package/dist/opt-in-settings.d.ts +69 -0
  101. package/dist/opt-in-settings.js +152 -0
  102. package/dist/recorder.d.ts +88 -0
  103. package/dist/recorder.js +538 -0
  104. package/dist/recordings.d.ts +116 -0
  105. package/dist/recordings.js +474 -0
  106. package/dist/redact.d.ts +7 -0
  107. package/dist/redact.js +18 -0
  108. package/dist/replay.d.ts +20 -0
  109. package/dist/replay.js +383 -0
  110. package/dist/reputation.d.ts +24 -2
  111. package/dist/reputation.js +63 -17
  112. package/dist/runtime-lock.js +3 -2
  113. package/dist/session-export.js +1 -1
  114. package/dist/session.d.ts +10 -2
  115. package/dist/session.js +10 -2
  116. package/dist/settings.d.ts +104 -2
  117. package/dist/settings.js +204 -6
  118. package/dist/sharing.d.ts +96 -0
  119. package/dist/sharing.js +269 -0
  120. package/dist/snippet.d.ts +8 -2
  121. package/dist/snippet.js +10 -4
  122. package/dist/tab-locks.d.ts +63 -0
  123. package/dist/tab-locks.js +179 -0
  124. package/dist/tools.d.ts +38 -0
  125. package/dist/tools.js +20 -1
  126. package/dist/tuning.d.ts +14 -0
  127. package/dist/tuning.js +9 -0
  128. package/dist/upstream.d.ts +11 -0
  129. package/dist/vault.js +5 -4
  130. package/npm-shrinkwrap.json +6 -5
  131. package/package.json +13 -7
package/dist/live.d.ts ADDED
@@ -0,0 +1,120 @@
1
+ import type { LiveSettings } from "./settings.js";
2
+ /**
3
+ * The live view and take-over, the part that needs no browser: the policy (identity.json `live`
4
+ * and the server flags), the pause gate that holds the agent's calls while the user acts, and
5
+ * the note that tells the agent what changed. The HTTP side and the screencast are in
6
+ * `live-server.ts`; the host wires both into every call (`host.ts`).
7
+ *
8
+ * How a pause works:
9
+ *
10
+ * - The user pauses (the live view's Pause button, or `turno browser pause <id>`). A call that is
11
+ * running finishes; the next call of any session waits, up to `live.wait` (2 minutes by
12
+ * default), for the user to resume. A batch or replay in progress stops at its next step.
13
+ * - On resume the held call gets a note first: how long the pause lasted and what changed in the
14
+ * browser's tabs (the current tab's URL and title, tabs opened and closed, input from the live
15
+ * view). When nothing changed, the call runs. When something changed, a call that only reads
16
+ * (a snapshot, the tab list) runs; any other call does not, because the refs of the agent's last
17
+ * snapshot may now point elsewhere, and a fresh snapshot comes back instead.
18
+ * - When the wait runs out the call fails with a message that says the user still has the
19
+ * browser; the next call waits again.
20
+ */
21
+ /** How long a paused call waits for the user when identity.json and the flags say nothing. */
22
+ export declare const DEFAULT_LIVE_WAIT_MS: number;
23
+ /** `turno-browser-mcp --live` and `--live-wait`: each wins over identity.json `live`. */
24
+ export interface LiveFlags {
25
+ live?: boolean;
26
+ waitMs?: number;
27
+ }
28
+ export interface LivePolicy {
29
+ enabled: boolean;
30
+ waitMs: number;
31
+ }
32
+ /** The live policy of a server: flags, then identity.json, then off. */
33
+ export declare function resolveLive(settings: LiveSettings | undefined, flags?: LiveFlags): LivePolicy;
34
+ /**
35
+ * Where a running server says how to reach its live view: its pid, the control socket and the
36
+ * port, never a token (`live-server.ts` writes it, `live-client.ts` reads it).
37
+ */
38
+ export declare function liveFilePath(id: string, env?: NodeJS.ProcessEnv): string;
39
+ export interface LiveFile {
40
+ version: 1;
41
+ pid: number;
42
+ socket: string;
43
+ port: number;
44
+ started: string;
45
+ }
46
+ /**
47
+ * Why the live view shows no pixels with this engine (read mode, attach mode, Camoufox);
48
+ * undefined when it can. Pause and resume
49
+ * work with every engine.
50
+ */
51
+ export declare function viewRefusal(engine: string | undefined): string | undefined;
52
+ /** One tab as the note compares it before and after a pause. */
53
+ export interface TabState {
54
+ id: number;
55
+ url: string;
56
+ title: string;
57
+ }
58
+ /** What a held call learns when the gate lets it go. */
59
+ export type GateOutcome = {
60
+ kind: "open";
61
+ } | {
62
+ kind: "resumed";
63
+ pausedMs: number;
64
+ by: string;
65
+ /** The tabs when the pause started (empty when no browser ran). */
66
+ before: TabState[];
67
+ /** Clicks, keys and scrolls the user sent through the live view during the pause. */
68
+ inputs: number;
69
+ } | {
70
+ kind: "timeout";
71
+ pausedMs: number;
72
+ by: string;
73
+ } | {
74
+ kind: "aborted";
75
+ };
76
+ /** Holds calls while the user has the browser. One per server: a pause holds every session. */
77
+ export declare class PauseGate {
78
+ private readonly now;
79
+ private pause;
80
+ private waiting;
81
+ constructor(now?: () => number);
82
+ get paused(): {
83
+ since: number;
84
+ by: string;
85
+ } | undefined;
86
+ /** Calls waiting for the user now. */
87
+ get held(): number;
88
+ /** Starts a pause; false when one is already on. `before` is the tabs as the agent left them. */
89
+ start(by: string, before?: Promise<TabState[]>): boolean;
90
+ /** Ends the pause and lets every held call go; false when there was none. */
91
+ resume(): boolean;
92
+ /** The user clicked, typed or scrolled through the live view. */
93
+ noteInput(): void;
94
+ /** Waits while paused, at most `waitMs`; resolves at once when there is no pause. */
95
+ wait(waitMs: number, signal?: AbortSignal): Promise<GateOutcome>;
96
+ }
97
+ /** `65000` as "1m 05s", `9000` as "9s". */
98
+ export declare function formatPause(ms: number): string;
99
+ /**
100
+ * What changed in the tabs between the pause and now, one line each, from the point of view
101
+ * of the session whose current tab was `currentBefore` and is `currentAfter` now.
102
+ */
103
+ export declare function describeChanges(before: readonly TabState[], after: readonly TabState[], currentBefore: number | undefined, currentAfter: number | undefined, inputs: number): {
104
+ changed: boolean;
105
+ lines: string[];
106
+ };
107
+ /** The section a held call's result starts with. */
108
+ export declare function resumeNote(o: {
109
+ pausedMs: number;
110
+ by: string;
111
+ lines: readonly string[];
112
+ tool: string;
113
+ ran: boolean;
114
+ /** A flow is being recorded: what the user did is not in it. */
115
+ recordingFlow?: boolean;
116
+ /** The browser is not running, so there is no snapshot. */
117
+ noBrowser?: boolean;
118
+ }): string;
119
+ /** The error of a call whose wait ran out. */
120
+ export declare function timeoutMessage(identity: string, tool: string, pausedMs: number, by: string, waitMs: number): string;
package/dist/live.js ADDED
@@ -0,0 +1,204 @@
1
+ import { join } from "node:path";
2
+ import { identityStateDir } from "./ids.js";
3
+ import { parseDuration } from "./units.js";
4
+ import { names } from "./names.js";
5
+ /**
6
+ * The live view and take-over, the part that needs no browser: the policy (identity.json `live`
7
+ * and the server flags), the pause gate that holds the agent's calls while the user acts, and
8
+ * the note that tells the agent what changed. The HTTP side and the screencast are in
9
+ * `live-server.ts`; the host wires both into every call (`host.ts`).
10
+ *
11
+ * How a pause works:
12
+ *
13
+ * - The user pauses (the live view's Pause button, or `turno browser pause <id>`). A call that is
14
+ * running finishes; the next call of any session waits, up to `live.wait` (2 minutes by
15
+ * default), for the user to resume. A batch or replay in progress stops at its next step.
16
+ * - On resume the held call gets a note first: how long the pause lasted and what changed in the
17
+ * browser's tabs (the current tab's URL and title, tabs opened and closed, input from the live
18
+ * view). When nothing changed, the call runs. When something changed, a call that only reads
19
+ * (a snapshot, the tab list) runs; any other call does not, because the refs of the agent's last
20
+ * snapshot may now point elsewhere, and a fresh snapshot comes back instead.
21
+ * - When the wait runs out the call fails with a message that says the user still has the
22
+ * browser; the next call waits again.
23
+ */
24
+ /** How long a paused call waits for the user when identity.json and the flags say nothing. */
25
+ export const DEFAULT_LIVE_WAIT_MS = 2 * 60_000;
26
+ /** The live policy of a server: flags, then identity.json, then off. */
27
+ export function resolveLive(settings, flags = {}) {
28
+ const wait = settings?.wait === undefined ? undefined : parseDuration(settings.wait);
29
+ return {
30
+ enabled: flags.live ?? settings?.enabled ?? false,
31
+ waitMs: flags.waitMs ?? wait ?? DEFAULT_LIVE_WAIT_MS,
32
+ };
33
+ }
34
+ /**
35
+ * Where a running server says how to reach its live view: its pid, the control socket and the
36
+ * port, never a token (`live-server.ts` writes it, `live-client.ts` reads it).
37
+ */
38
+ export function liveFilePath(id, env = process.env) {
39
+ return join(identityStateDir(id, env), "live.json");
40
+ }
41
+ /**
42
+ * Why the live view shows no pixels with this engine (read mode, attach mode, Camoufox);
43
+ * undefined when it can. Pause and resume
44
+ * work with every engine.
45
+ */
46
+ export function viewRefusal(engine) {
47
+ if (engine === "lightpanda")
48
+ return "Read mode (Lightpanda) renders no pixels, so there is nothing to show. Pause and resume still work.";
49
+ if (engine === "attach")
50
+ return "Attach mode drives your own Chrome, which you already see; a view would stream your own tabs, so it is off. Pause and resume still work.";
51
+ if (engine === "camoufox")
52
+ return "The view is a Chrome DevTools Protocol screencast, and Camoufox is a Firefox build that has none, so there is nothing to show; Camoufox's own window shows the page when it runs headed. Pause and resume still work.";
53
+ return undefined;
54
+ }
55
+ /** Holds calls while the user has the browser. One per server: a pause holds every session. */
56
+ export class PauseGate {
57
+ now;
58
+ pause;
59
+ waiting = 0;
60
+ constructor(now = Date.now) {
61
+ this.now = now;
62
+ }
63
+ get paused() {
64
+ return this.pause && { since: this.pause.since, by: this.pause.by };
65
+ }
66
+ /** Calls waiting for the user now. */
67
+ get held() {
68
+ return this.waiting;
69
+ }
70
+ /** Starts a pause; false when one is already on. `before` is the tabs as the agent left them. */
71
+ start(by, before = Promise.resolve([])) {
72
+ if (this.pause)
73
+ return false;
74
+ let release;
75
+ const done = new Promise((r) => {
76
+ release = r;
77
+ });
78
+ before.catch(() => { });
79
+ this.pause = { since: this.now(), by, before, inputs: 0, done, release };
80
+ return true;
81
+ }
82
+ /** Ends the pause and lets every held call go; false when there was none. */
83
+ resume() {
84
+ const p = this.pause;
85
+ if (!p)
86
+ return false;
87
+ this.pause = undefined;
88
+ p.release();
89
+ return true;
90
+ }
91
+ /** The user clicked, typed or scrolled through the live view. */
92
+ noteInput() {
93
+ if (this.pause)
94
+ this.pause.inputs++;
95
+ }
96
+ /** Waits while paused, at most `waitMs`; resolves at once when there is no pause. */
97
+ async wait(waitMs, signal) {
98
+ const p = this.pause;
99
+ if (!p)
100
+ return { kind: "open" };
101
+ if (signal?.aborted)
102
+ return { kind: "aborted" };
103
+ this.waiting++;
104
+ let timer;
105
+ let onAbort;
106
+ try {
107
+ const outcome = await Promise.race([
108
+ p.done.then(() => "resumed"),
109
+ new Promise((r) => {
110
+ // Each call waits the whole time: a call that arrives late in a pause is held as long.
111
+ timer = setTimeout(() => r("timeout"), waitMs);
112
+ }),
113
+ new Promise((r) => {
114
+ onAbort = () => r("aborted");
115
+ signal?.addEventListener("abort", onAbort, { once: true });
116
+ }),
117
+ ]);
118
+ if (outcome === "aborted")
119
+ return { kind: "aborted" };
120
+ const pausedMs = this.now() - p.since;
121
+ if (outcome === "timeout")
122
+ return { kind: "timeout", pausedMs, by: p.by };
123
+ return { kind: "resumed", pausedMs, by: p.by, before: await p.before.catch(() => []), inputs: p.inputs };
124
+ }
125
+ finally {
126
+ this.waiting--;
127
+ if (timer)
128
+ clearTimeout(timer);
129
+ if (onAbort)
130
+ signal?.removeEventListener("abort", onAbort);
131
+ }
132
+ }
133
+ }
134
+ /** `65000` as "1m 05s", `9000` as "9s". */
135
+ export function formatPause(ms) {
136
+ const s = Math.max(0, Math.round(ms / 1000));
137
+ if (s < 60)
138
+ return `${s}s`;
139
+ const m = Math.floor(s / 60);
140
+ return `${m}m ${String(s % 60).padStart(2, "0")}s`;
141
+ }
142
+ /**
143
+ * What changed in the tabs between the pause and now, one line each, from the point of view
144
+ * of the session whose current tab was `currentBefore` and is `currentAfter` now.
145
+ */
146
+ export function describeChanges(before, after, currentBefore, currentAfter, inputs) {
147
+ const lines = [];
148
+ const was = new Map(before.map((t) => [t.id, t]));
149
+ const now = new Map(after.map((t) => [t.id, t]));
150
+ const cb = currentBefore === undefined ? undefined : was.get(currentBefore);
151
+ const ca = currentAfter === undefined ? undefined : now.get(currentAfter);
152
+ if (cb && ca && cb.id === ca.id) {
153
+ if (cb.url !== ca.url)
154
+ lines.push(`Current tab: ${cb.url} -> ${ca.url}`);
155
+ if (cb.title !== ca.title)
156
+ lines.push(`Title: ${JSON.stringify(cb.title)} -> ${JSON.stringify(ca.title)}`);
157
+ }
158
+ else if (ca && currentBefore !== undefined) {
159
+ lines.push(`Current tab is now another tab: ${ca.url} (${JSON.stringify(ca.title)})`);
160
+ }
161
+ for (const t of after)
162
+ if (!was.has(t.id))
163
+ lines.push(`New tab: ${t.url}`);
164
+ for (const t of before)
165
+ if (!now.has(t.id))
166
+ lines.push(`Closed tab: ${t.url}`);
167
+ for (const t of after) {
168
+ const old = was.get(t.id);
169
+ if (!old || t.id === ca?.id || t.id === cb?.id)
170
+ continue;
171
+ if (old.url !== t.url)
172
+ lines.push(`Another tab: ${old.url} -> ${t.url}`);
173
+ }
174
+ if (inputs > 0)
175
+ lines.push(`The user clicked, typed or scrolled ${inputs} time${inputs === 1 ? "" : "s"} through the live view.`);
176
+ return { changed: lines.length > 0, lines };
177
+ }
178
+ /** The section a held call's result starts with. */
179
+ export function resumeNote(o) {
180
+ const out = [
181
+ "### Paused by the user",
182
+ `The user paused this browser (${o.by}) for ${formatPause(o.pausedMs)} and has resumed it.`,
183
+ ];
184
+ if (o.lines.length)
185
+ out.push("While you waited:", ...o.lines.map((l) => `- ${l}`));
186
+ else
187
+ out.push("Nothing changed in the browser's tabs (same tabs, URLs and titles).");
188
+ if (o.ran)
189
+ out.push(`Your ${o.tool} call ran after the resume; its result follows.`);
190
+ else if (o.noBrowser)
191
+ out.push(`Your ${o.tool} call was not run. The browser is not running now; start again from a navigation.`);
192
+ else
193
+ out.push(`Your ${o.tool} call was not run: the browser changed while you waited, so the refs of your last snapshot may point elsewhere. A fresh snapshot follows; decide the next step from it.`);
194
+ if (o.recordingFlow)
195
+ out.push("The flow you are recording does not have what the user did.");
196
+ return out.join("\n");
197
+ }
198
+ /** The error of a call whose wait ran out. */
199
+ export function timeoutMessage(identity, tool, pausedMs, by, waitMs) {
200
+ return (`The user paused browser identity "${identity}" ${formatPause(pausedMs)} ago (${by}) and has not resumed it ` +
201
+ `within ${formatPause(waitMs)}, so ${tool} was not run. The user is probably acting in the browser: wait, or ask ` +
202
+ `them to resume (Resume in the live view, or ${names().browser} resume ${identity}), then call again.`);
203
+ }
204
+ //# sourceMappingURL=live.js.map
@@ -1,5 +1,7 @@
1
+ import type { Page } from "patchright-core";
1
2
  import type { SecretStore } from "turno-core/secrets";
2
3
  import type { IdentityRef } from "./engine.js";
4
+ import type { HumanInput } from "./human-input.js";
3
5
  import type { Redactor, VaultGuard } from "./redact.js";
4
6
  import type { TurnoTool } from "./tools.js";
5
7
  /**
@@ -25,6 +27,17 @@ export interface VaultAccess {
25
27
  guard: VaultGuard;
26
28
  /** The secret store (tests inject a fake); default: this machine's. */
27
29
  store?: SecretStore;
30
+ /**
31
+ * Runs before a value goes into the page: a recording saves its trace and holds the page,
32
+ * so the fill is never traced or screenshotted (`recordings.ts`).
33
+ */
34
+ beforeFill?: (page: Page) => Promise<void>;
35
+ /**
36
+ * Human-like input, when the identity's humanize is on: each value is typed key by key into
37
+ * its field, as `browser_type` would. Keys go to Chrome's input pipeline and nowhere else:
38
+ * not into a result (the redactor), a trace (`beforeFill` stopped it) or a log.
39
+ */
40
+ input?: HumanInput;
28
41
  }
29
42
  /** The tool. Its schema is built on first use, so importing the registry does not load the bundle. */
30
43
  export declare function loginTool(): TurnoTool;
@@ -1,6 +1,7 @@
1
1
  import { totp, totpSecondsLeft } from "./totp.js";
2
2
  import { upstream } from "./upstream.js";
3
3
  import { VaultError, originAllowed, readCredential, vaultSite } from "./vault.js";
4
+ import { names as commandNames } from "./names.js";
4
5
  const TEXT = ':not([type="password"]):not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"])';
5
6
  const SELECTORS = {
6
7
  password: 'input[type="password"]',
@@ -49,7 +50,7 @@ function schema() {
49
50
  "You name the site; the values are never shown to you, and they are hidden from every later result of this server.",
50
51
  "The current page must be on the site's own sign-in page (the origins it was stored with).",
51
52
  "Fields found on the page are filled (a two-step sign-in needs one call per step). It does not submit the form unless the identity allows it: click the sign-in button yourself afterwards.",
52
- "The person adds credentials with `turno browser vault add <identity> <site>`.",
53
+ `The person adds credentials with \`${commandNames().browser} vault add <identity> <site>\`.`,
53
54
  ].join(" "),
54
55
  inputSchema: z.object({
55
56
  site: z.string().describe("The site key in the vault, for example github"),
@@ -119,7 +120,7 @@ export function loginTool() {
119
120
  const siteKey = params.site;
120
121
  const found = vaultSite(id, siteKey, env);
121
122
  if (!found)
122
- throw new VaultError(`identity "${id}" has no credentials for "${siteKey}" in its vault; the person adds them with: turno browser vault add ${id} ${siteKey} --url <sign-in page>`);
123
+ throw new VaultError(`identity "${id}" has no credentials for "${siteKey}" in its vault; the person adds them with: ${commandNames().browser} vault add ${id} ${siteKey} --url <sign-in page>`);
123
124
  const { site, submit } = found;
124
125
  const page = ctx.stock?.currentPage();
125
126
  if (!page)
@@ -156,6 +157,7 @@ export function loginTool() {
156
157
  code = totp(credential.totp);
157
158
  }
158
159
  }
160
+ await vault.beforeFill?.(page);
159
161
  // Redact first: from here on no result or error of this server shows a value.
160
162
  vault.redactor.add(credential.username, `${siteKey} username`);
161
163
  vault.redactor.add(credential.password, `${siteKey} password`);
@@ -169,7 +171,10 @@ export function loginTool() {
169
171
  };
170
172
  const filled = [];
171
173
  let last;
172
- for (const [field, locator] of fields) {
174
+ // With humanize on, the fields are clicked into and typed key by key (`human-input.ts`).
175
+ const humanized = vault.input && vault.input.levelFor(page) !== "off" ? vault.input : undefined;
176
+ for (const [field, found] of fields) {
177
+ const locator = humanized ? humanized.wrapLocator(found, page) : found;
173
178
  try {
174
179
  await locator.fill(values[field], { timeout: 5_000 });
175
180
  }
package/dist/login.d.ts CHANGED
@@ -4,10 +4,13 @@ export interface LoginOptions {
4
4
  url?: string;
5
5
  }
6
6
  /**
7
- * Opens the identity's persistent Chrome headed, with the same stealth settings as the MCP
7
+ * Opens the identity's persistent Chrome headed, with the same launch settings as the MCP
8
8
  * server (Chrome channel, no fixed viewport, the identity's languages and time zone), and
9
9
  * resolves when the user closes the last window or quits Chrome. Used once per site so the user
10
10
  * signs in by hand. It holds the identity's runtime lock while the window is open, and clears
11
11
  * the last session health result, so the next launch checks the sign-in again.
12
+ *
13
+ * With identity.json `proxy`, the sign-in goes through the same proxy as the agent's sessions,
14
+ * so the site sees one network for both. A Camoufox identity is refused: it keeps its own profile.
12
15
  */
13
16
  export declare function loginIdentity(id: string, options?: LoginOptions): Promise<void>;
package/dist/login.js CHANGED
@@ -2,14 +2,19 @@ import { mkdirSync } from "node:fs";
2
2
  import { clearHealth } from "./health.js";
3
3
  import { IdentityError, identityDir, inUseBy, isInUse } from "./identities.js";
4
4
  import { readLockPid } from "./lifecycle.js";
5
+ import { CHROME_PROXY_ARGS, resolveProxy } from "./network.js";
5
6
  import { acquireRuntimeLock } from "./runtime-lock.js";
6
7
  import { chromeEnv, keychainArgs, launchSettings, readIdentitySettings, systemTimezone } from "./settings.js";
8
+ import { names } from "./names.js";
7
9
  /**
8
- * Opens the identity's persistent Chrome headed, with the same stealth settings as the MCP
10
+ * Opens the identity's persistent Chrome headed, with the same launch settings as the MCP
9
11
  * server (Chrome channel, no fixed viewport, the identity's languages and time zone), and
10
12
  * resolves when the user closes the last window or quits Chrome. Used once per site so the user
11
13
  * signs in by hand. It holds the identity's runtime lock while the window is open, and clears
12
14
  * the last session health result, so the next launch checks the sign-in again.
15
+ *
16
+ * With identity.json `proxy`, the sign-in goes through the same proxy as the agent's sessions,
17
+ * so the site sees one network for both. A Camoufox identity is refused: it keeps its own profile.
13
18
  */
14
19
  export async function loginIdentity(id, options = {}) {
15
20
  const env = options.env ?? process.env;
@@ -20,6 +25,10 @@ export async function loginIdentity(id, options = {}) {
20
25
  if (isInUse(id, env))
21
26
  throw new IdentityError(`identity "${id}" is in use (an MCP session holds its Chrome); close it first`);
22
27
  const settings = readIdentitySettings(id, env);
28
+ if (settings?.engine === "camoufox" && settings.attach === undefined)
29
+ throw new IdentityError(`identity "${id}" runs on Camoufox, which keeps its own profile, and \`${names().browser} login\` opens the Chrome profile: sign in from an agent session (browser_login with the vault), or use --engine chrome`);
30
+ // Read before the lock, so a missing secret leaves nothing to undo; the value goes only to Chrome.
31
+ const proxy = settings?.proxy ? await resolveProxy(settings.proxy, env, () => { }) : undefined;
23
32
  const held = acquireRuntimeLock(id, env, { holder: "login" });
24
33
  try {
25
34
  mkdirSync(dir, { recursive: true, mode: 0o700 });
@@ -29,7 +38,8 @@ export async function loginIdentity(id, options = {}) {
29
38
  channel: "chrome",
30
39
  headless: false,
31
40
  viewport: null,
32
- ...(applied.args.length ? { args: applied.args } : {}),
41
+ ...(applied.args.length || proxy ? { args: [...applied.args, ...(proxy ? CHROME_PROXY_ARGS : [])] } : {}),
42
+ ...(proxy ? { proxy } : {}),
33
43
  ...(applied.timezoneId ? { timezoneId: applied.timezoneId } : {}),
34
44
  ...keychainArgs(settings),
35
45
  // Chrome gets the caller's environment (HOME, XDG dirs), not this process's.
@@ -0,0 +1,28 @@
1
+ /**
2
+ * How the commands a message suggests are typed. turno-browser's own commands work for every
3
+ * install, so messages name them by default (`turno-browser login school`), the MCP server's
4
+ * included. When turno-cli runs the identity commands as `turno browser <cmd>` and
5
+ * `turno identity ... browser:<id>`, its host sets turno's names for that process, so its
6
+ * hints, errors and doctor fixes keep naming the commands the person typed.
7
+ */
8
+ /** How the commands are typed, for hints, examples and messages. */
9
+ export interface CliNames {
10
+ /** The program, as errors start: `turno-browser` or `turno`. */
11
+ program: string;
12
+ /** How a browser subcommand is typed: `turno-browser` or `turno browser`. */
13
+ browser: string;
14
+ /** The word messages put before a subcommand name: "" or "browser ". */
15
+ subject: string;
16
+ /** How a command on one identity is typed: `turno-browser add school`, `turno identity add browser:school`. */
17
+ identity(sub: string, id: string): string;
18
+ /** How a person stores a secret store item that a `keychain:<item>` reference names. */
19
+ secretSet(item: string): string;
20
+ /** The secret store in short, where a line has no room for `secretSet` (default: `secretSet("<item>")`). */
21
+ secretStore?: string;
22
+ }
23
+ /** The names of turno-browser on its own. */
24
+ export declare const STANDALONE_NAMES: CliNames;
25
+ /** The names messages of this process use. */
26
+ export declare function names(): CliNames;
27
+ /** Use `n` for the messages of this process (a host's names); `STANDALONE_NAMES` restores. */
28
+ export declare function useNames(n: CliNames): void;
package/dist/names.js ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * How the commands a message suggests are typed. turno-browser's own commands work for every
3
+ * install, so messages name them by default (`turno-browser login school`), the MCP server's
4
+ * included. When turno-cli runs the identity commands as `turno browser <cmd>` and
5
+ * `turno identity ... browser:<id>`, its host sets turno's names for that process, so its
6
+ * hints, errors and doctor fixes keep naming the commands the person typed.
7
+ */
8
+ /** The names of turno-browser on its own. */
9
+ export const STANDALONE_NAMES = {
10
+ program: "turno-browser",
11
+ browser: "turno-browser",
12
+ subject: "",
13
+ identity: (sub, id) => `turno-browser ${sub} ${id}`,
14
+ secretSet: (item) => `turno-browser secret set ${item}`,
15
+ };
16
+ let current = STANDALONE_NAMES;
17
+ /** The names messages of this process use. */
18
+ export function names() {
19
+ return current;
20
+ }
21
+ /** Use `n` for the messages of this process (a host's names); `STANDALONE_NAMES` restores. */
22
+ export function useNames(n) {
23
+ current = n;
24
+ }
25
+ //# sourceMappingURL=names.js.map
@@ -0,0 +1,74 @@
1
+ import type { BrowserContext, Page } from "patchright-core";
2
+ import { type ExpectedIdentity, type ResolvedProxy } from "./network.js";
3
+ import { type IdentitySettings } from "./settings.js";
4
+ import type { McpConfig } from "./upstream.js";
5
+ /**
6
+ * How the chrome engine applies identity.json `proxy` and `userAgent` (`network.ts`). Both are
7
+ * settled before Chrome starts: a missing secret or an unknown Chrome version stops the launch
8
+ * with nothing to undo.
9
+ *
10
+ * `userAgent: "coherent"` changes nothing in a headed Chrome, which already presents itself
11
+ * as it is; the launch check still runs. A headless Chrome says HeadlessChrome, so it gets two
12
+ * things, measured with Chrome 157:
13
+ *
14
+ * - the `--user-agent` switch with the headed string for the same version and OS, which every
15
+ * request, popup and worker carries from the start; on its own it blanks the client hints'
16
+ * high entropy values (full version list, architecture, platform version), which a real
17
+ * Chrome never does;
18
+ * - so each page also gets those values back through `Emulation.setUserAgentOverride`, with
19
+ * the metadata this same Chrome reports when nothing overrides it, read once per Chrome
20
+ * version by a short headless launch on a throwaway profile and kept in the state folder.
21
+ * Dedicated workers take them from their page.
22
+ *
23
+ * A tab a tool opens gets them before its first navigation. A popup a page opens gets them as
24
+ * soon as it exists, which can be after its first document loaded: that document reads blank
25
+ * high entropy values (the user agent string is right there too).
26
+ */
27
+ export interface ChromeNetwork {
28
+ /** Chrome switches to add. */
29
+ args: string[];
30
+ /** Playwright's `proxy` launch option, credentials included. */
31
+ proxy?: ResolvedProxy;
32
+ /** With `userAgent`, what the launch check expects the page to read. */
33
+ verify?: ExpectedIdentity;
34
+ /** With `userAgent` in a headless Chrome: the string and metadata each page gets. */
35
+ pin?: UserAgentPin;
36
+ }
37
+ /** The client hints metadata of `Emulation.setUserAgentOverride`, as this Chrome reports it. */
38
+ interface UserAgentMetadata {
39
+ brands: {
40
+ brand: string;
41
+ version: string;
42
+ }[];
43
+ fullVersionList: {
44
+ brand: string;
45
+ version: string;
46
+ }[];
47
+ platform: string;
48
+ platformVersion: string;
49
+ architecture: string;
50
+ model: string;
51
+ mobile: boolean;
52
+ bitness: string;
53
+ wow64: boolean;
54
+ }
55
+ export interface UserAgentPin {
56
+ userAgent: string;
57
+ metadata: UserAgentMetadata;
58
+ }
59
+ export declare function chromeNetwork(settings: IdentitySettings, config: McpConfig, env: NodeJS.ProcessEnv, secret: (value: string, label: string) => void): Promise<ChromeNetwork>;
60
+ /** Gives every page of the context the pinned user agent and metadata; `ready` resolves once a page has them. */
61
+ export declare function pinUserAgent(context: BrowserContext, pin: UserAgentPin): {
62
+ ready(page: Page): Promise<void>;
63
+ };
64
+ /**
65
+ * The launch check of `userAgent: "coherent"`: loads a blank page of its own on an https origin
66
+ * (client hints exist only in a secure context), answered by a route so no request leaves the
67
+ * machine, reads what the page sees and what the request carried, and refuses the browser when
68
+ * anything contradicts the rest, or the user agent names another version than the Chrome that
69
+ * runs. A headed Chrome shows that tab for a moment. The caller closes the browser on a throw.
70
+ */
71
+ export declare function verifyCoherence(context: BrowserContext, version: string, expected: ExpectedIdentity, pinned?: {
72
+ ready(page: Page): Promise<void>;
73
+ }): Promise<void>;
74
+ export {};