@cydm/pie 4.8.0 → 4.9.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/README.md +51 -27
- package/dist/builtin/extensions/ask-user/index.js +4 -4
- package/dist/builtin/extensions/cron/index.js +906 -158
- package/dist/builtin/extensions/im-forward/README.md +4 -2
- package/dist/builtin/extensions/im-forward/index.js +6822 -3951
- package/dist/builtin/extensions/memory/index.js +76 -28
- package/dist/builtin/extensions/pie-ipc/README.md +2 -2
- package/dist/builtin/extensions/pie-ipc/index.js +282 -58
- package/dist/builtin/extensions/pie-proc/README.md +7 -7
- package/dist/builtin/extensions/pie-proc/index.js +227 -75
- package/dist/builtin/extensions/plan-mode/index.js +5 -5
- package/dist/builtin/extensions/subagent/index.js +8 -8
- package/dist/builtin/extensions/todo/index.js +4 -4
- package/dist/builtin/skills/chrome-devtools-axi/SKILL.md +26 -24
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +199 -121
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/chunk-HAUDUMDO.js +795 -0
- package/dist/builtin/skills/chrome-devtools-axi/{cli-ZE754CTH.js → cli-K7ESY3XD.js} +433 -255
- package/dist/builtin/skills/computer-use-axi/SKILL.md +25 -8
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +293 -64
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-runtime.js +2 -2
- package/dist/builtin/skills/tui-use/tui-use-daemon.cjs +451 -43
- package/dist/chunks/{chunk-3W3SXVPB.js → chunk-4UIUMTHG.js} +993 -371
- package/dist/chunks/chunk-6WKBQZWM.js +19 -0
- package/dist/chunks/{chunk-5KI4Y4LA.js → chunk-BA4Z27XT.js} +4 -3
- package/dist/chunks/{chunk-BLDI2GRF.js → chunk-DBDU3RRN.js} +1364 -446
- package/dist/chunks/{chunk-LAJXWOKS.js → chunk-EEC5PJTC.js} +11 -9
- package/dist/chunks/chunk-IZKHSUNQ.js +30 -0
- package/dist/chunks/{chunk-Y3I2UV5Y.js → chunk-LRHNAG4V.js} +349 -288
- package/dist/chunks/chunk-OU33ROFD.js +717 -0
- package/dist/chunks/{chunk-Z2FKA2ZH.js → chunk-PN6B54VT.js} +104 -22
- package/dist/chunks/{chunk-NHV2CALB.js → chunk-WYXUF4MP.js} +388 -32
- package/dist/chunks/{chunk-4PR34UZF.js → chunk-Z5KL6AO2.js} +159 -145
- package/dist/chunks/{host-image-fallback-N7RHNPYN.js → host-image-fallback-RASJSVZY.js} +1 -1
- package/dist/chunks/{manager-cli-NEZA46M5.js → manager-cli-Y6HM3MHA.js} +5 -5
- package/dist/chunks/{model-registry-3XAHXXTA.js → model-registry-5TLYILYR.js} +2 -2
- package/dist/chunks/{read-file-understanding-FMPXR6EJ.js → read-file-understanding-VPKDBV23.js} +5 -5
- package/dist/chunks/{src-B44QWSGM.js → src-2XI5P62J.js} +2 -2
- package/dist/chunks/{src-EGXFJ3WA.js → src-6QGGDHIW.js} +3 -3
- package/dist/chunks/{src-Q7LU27C2.js → src-CCEENRKC.js} +31 -1
- package/dist/chunks/{src-CLE5ILN4.js → src-DI4MCAGT.js} +20 -4
- package/dist/chunks/{test-stream-OR3EJBNF.js → test-stream-SYVWIPPW.js} +2 -2
- package/dist/cli.js +1890 -1489
- package/models.schema.json +271 -0
- package/package.json +2 -2
- package/dist/builtin/skills/chrome-devtools-axi/chunk-Z2A5LA5A.js +0 -407
- package/dist/chunks/chunk-EGZ5TZRM.js +0 -1444
- package/dist/chunks/{chunk-CGSFBWOM.js → chunk-WBL73KRI.js} +3 -3
- package/dist/chunks/{manager-upgrade-CTU3ISCW.js → manager-upgrade-LSTOHBUV.js} +3 -3
|
@@ -13,7 +13,19 @@ bash.exe):
|
|
|
13
13
|
node <baseDir>/computer-use-axi-cli.js <command> [options]
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
Desktop control is a last resort —
|
|
16
|
+
Desktop control is a last resort — follow this **background-first hierarchy**
|
|
17
|
+
so you never hijack the user's computer unnecessarily:
|
|
18
|
+
1. Plain API / CLI / web tools (`web_research`, `shell`).
|
|
19
|
+
2. Isolated headless browser (`chrome-devtools-axi` default, or `browser launch`
|
|
20
|
+
here which now launches headless `--headless=new` in the background by default).
|
|
21
|
+
3. Background semantic AX/UIA (`observe` is non-activating; for unattended
|
|
22
|
+
desktop automation set `PIE_COMPUTER_USE_DELIVERY_POLICY=background` or
|
|
23
|
+
`ax_only` so actions fail closed with `foreground_required` instead of
|
|
24
|
+
stealing the user's window focus or cursor).
|
|
25
|
+
4. Foreground HID input (`PIE_COMPUTER_USE_DELIVERY_POLICY=foreground` or
|
|
26
|
+
default escalation) ONLY when the user explicitly asked for visible/physical
|
|
27
|
+
desktop interaction and no background semantic/CDP path works.
|
|
28
|
+
|
|
17
29
|
First use on macOS installs the `pie-computer-use.app` helper; the CLI then
|
|
18
30
|
reports missing Accessibility and Screen Recording permissions. Use the real
|
|
19
31
|
non-TUI setup flow (the user grants toggles in macOS Settings):
|
|
@@ -136,10 +148,12 @@ node <baseDir>/computer-use-axi-cli.js act --state S1 --actions '[
|
|
|
136
148
|
but only within the same root: a modal/sheet or a closing window is a NEW
|
|
137
149
|
root, so expect cannot see it; run the action without `--expect` and read
|
|
138
150
|
the returned root note instead.
|
|
139
|
-
- Focus-following works only inside one act transaction
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
151
|
+
- Focus-following works only inside one act transaction and uses shared OS
|
|
152
|
+
foreground focus — avoid ref-less `typeText`/`keypress` for background tasks
|
|
153
|
+
(prefer ref-based `setText` or CDP instead). Under `background`/`ax_only`
|
|
154
|
+
policy, foreground-only actions fail closed with `foreground_required` rather
|
|
155
|
+
than stealing focus. A standalone keypress (for example `["cmd","w"]`) must
|
|
156
|
+
carry `ref` (the window or a specific element).
|
|
143
157
|
- On failure the output still names the successor state — inspect it instead
|
|
144
158
|
of blindly replaying.
|
|
145
159
|
- Acting requires the platform helper: on macOS first use installs
|
|
@@ -166,9 +180,12 @@ node <baseDir>/computer-use-axi-cli.js browser eval --state S1 --expr 'document.
|
|
|
166
180
|
```
|
|
167
181
|
|
|
168
182
|
Browser states use the same outline/action/condition contracts as desktop
|
|
169
|
-
states.
|
|
170
|
-
`
|
|
171
|
-
|
|
183
|
+
states. `browser launch` starts an isolated **background headless** browser
|
|
184
|
+
(`--headless=new`) by default so it does not pop a window over the user's
|
|
185
|
+
desktop; set `PIE_COMPUTER_USE_BROWSER_HEADED=1` only when a visible managed
|
|
186
|
+
browser window is explicitly needed. Native browser windows are ordinary
|
|
187
|
+
desktop UI — use `roots`/`observe`/`act` on them. Browser control may need
|
|
188
|
+
enabling via the computer-use config (`browser_use`).
|
|
172
189
|
|
|
173
190
|
## Test-only backend
|
|
174
191
|
|
|
@@ -70,6 +70,7 @@ function resolveTestOnlyBackend(env = process.env) {
|
|
|
70
70
|
}
|
|
71
71
|
var init_test_backend_guard = __esm({
|
|
72
72
|
"vendor/computer-use-axi/src/test-backend-guard.ts"() {
|
|
73
|
+
"use strict";
|
|
73
74
|
}
|
|
74
75
|
});
|
|
75
76
|
|
|
@@ -90,6 +91,7 @@ function toOptionalString(value) {
|
|
|
90
91
|
}
|
|
91
92
|
var init_coerce = __esm({
|
|
92
93
|
"vendor/computer-use-axi/src/platform/coerce.ts"() {
|
|
94
|
+
"use strict";
|
|
93
95
|
}
|
|
94
96
|
});
|
|
95
97
|
|
|
@@ -3813,6 +3815,7 @@ function resolvePieConfigDir(env, homeDir) {
|
|
|
3813
3815
|
var HELPER_APP_NAME, SYSTEM_HELPER_APP_PATH;
|
|
3814
3816
|
var init_helper_path = __esm({
|
|
3815
3817
|
"vendor/computer-use-axi/src/platform/macos/helper-path.mjs"() {
|
|
3818
|
+
"use strict";
|
|
3816
3819
|
HELPER_APP_NAME = "pie-computer-use.app";
|
|
3817
3820
|
SYSTEM_HELPER_APP_PATH = path7.join("/Applications", HELPER_APP_NAME);
|
|
3818
3821
|
}
|
|
@@ -3836,6 +3839,7 @@ function resolveExtensionRoot(moduleUrl) {
|
|
|
3836
3839
|
}
|
|
3837
3840
|
var init_package_root = __esm({
|
|
3838
3841
|
"vendor/computer-use-axi/src/platform/package-root.ts"() {
|
|
3842
|
+
"use strict";
|
|
3839
3843
|
}
|
|
3840
3844
|
});
|
|
3841
3845
|
|
|
@@ -3926,6 +3930,7 @@ ${output}`.trim()));
|
|
|
3926
3930
|
var COMMAND_TIMEOUT_MS2, HELPER_PROTOCOL_VERSION, HELPER_SETUP_TIMEOUT_MS, HELPER_APP_PATH, HELPER_APP_EXECUTABLE_PATH, DEFAULT_HELPER_SOCKET_PATH, HELPER_SOCKET_PATH, usingExternalHelperSocket, PACKAGE_ROOT, SETUP_HELPER_SCRIPT, HelperTransportError, HelperCommandError, MacosHelperClient, macosHelper;
|
|
3927
3931
|
var init_helper = __esm({
|
|
3928
3932
|
"vendor/computer-use-axi/src/platform/macos/helper.ts"() {
|
|
3933
|
+
"use strict";
|
|
3929
3934
|
init_test_backend_guard();
|
|
3930
3935
|
init_coerce();
|
|
3931
3936
|
init_helper_path();
|
|
@@ -4165,6 +4170,7 @@ async function ensurePermissions(ctx, bridge, helperPath, signal) {
|
|
|
4165
4170
|
}
|
|
4166
4171
|
var init_permissions = __esm({
|
|
4167
4172
|
"vendor/computer-use-axi/src/permissions.ts"() {
|
|
4173
|
+
"use strict";
|
|
4168
4174
|
}
|
|
4169
4175
|
});
|
|
4170
4176
|
|
|
@@ -4182,6 +4188,7 @@ function assertPlatformArchitecture(platform, diagnostics) {
|
|
|
4182
4188
|
var PLATFORM_ARCHITECTURE_VERSION, REQUIRED_PLATFORM_INVARIANTS;
|
|
4183
4189
|
var init_architecture = __esm({
|
|
4184
4190
|
"vendor/computer-use-axi/src/platform/architecture.ts"() {
|
|
4191
|
+
"use strict";
|
|
4185
4192
|
PLATFORM_ARCHITECTURE_VERSION = 1;
|
|
4186
4193
|
REQUIRED_PLATFORM_INVARIANTS = [
|
|
4187
4194
|
"state-scoped-observations",
|
|
@@ -4327,6 +4334,7 @@ Helper path: ${helperPath}`,
|
|
|
4327
4334
|
var GRANT_INSTRUCTIONS, SIGNING_MIGRATION_WARNING, macosPermissionKinds, registeredForHelperPid, autoRestartAttempted;
|
|
4328
4335
|
var init_permissions2 = __esm({
|
|
4329
4336
|
"vendor/computer-use-axi/src/platform/macos/permissions.ts"() {
|
|
4337
|
+
"use strict";
|
|
4330
4338
|
init_permissions();
|
|
4331
4339
|
init_coerce();
|
|
4332
4340
|
init_helper();
|
|
@@ -4422,14 +4430,14 @@ var DEFAULT_CONFIG = {
|
|
|
4422
4430
|
cursor_overlay: true,
|
|
4423
4431
|
managed_browser: "chrome"
|
|
4424
4432
|
};
|
|
4425
|
-
var REQUEST_ENV_KEYS = ["PIE_COMPUTER_USE_BROWSER_USE", "PIE_COMPUTER_USE_HEADLESS", "PIE_COMPUTER_USE_CURSOR_OVERLAY", "PIE_COMPUTER_USE_MANAGED_BROWSER", "PIE_COMPUTER_USE_HELIUM_EXECUTABLE", "PIE_COMPUTER_USE_CHROME_EXECUTABLE", "PIE_COMPUTER_USE_CDP_PORT", "PIE_COMPUTER_USE_DELIVERY_POLICY", "PIE_COMPUTER_USE_EVENT_DELIVERY"];
|
|
4433
|
+
var REQUEST_ENV_KEYS = ["PIE_COMPUTER_USE_BROWSER_USE", "PIE_COMPUTER_USE_HEADLESS", "PIE_COMPUTER_USE_BROWSER_HEADED", "PIE_COMPUTER_USE_CURSOR_OVERLAY", "PIE_COMPUTER_USE_MANAGED_BROWSER", "PIE_COMPUTER_USE_HELIUM_EXECUTABLE", "PIE_COMPUTER_USE_CHROME_EXECUTABLE", "PIE_COMPUTER_USE_CDP_PORT", "PIE_COMPUTER_USE_DELIVERY_POLICY", "PIE_COMPUTER_USE_EVENT_DELIVERY"];
|
|
4426
4434
|
function captureComputerUseEnvironment(env = process.env) {
|
|
4427
4435
|
const out = {};
|
|
4428
4436
|
for (const key of REQUEST_ENV_KEYS) {
|
|
4429
4437
|
const value = env[key]?.trim();
|
|
4430
4438
|
if (!value) continue;
|
|
4431
4439
|
if (Buffer.byteLength(value) > 4096 || value.includes("\0")) throw new Error(`Invalid ${key}`);
|
|
4432
|
-
if (["PIE_COMPUTER_USE_BROWSER_USE", "PIE_COMPUTER_USE_HEADLESS", "PIE_COMPUTER_USE_CURSOR_OVERLAY"].includes(key)) {
|
|
4440
|
+
if (["PIE_COMPUTER_USE_BROWSER_USE", "PIE_COMPUTER_USE_HEADLESS", "PIE_COMPUTER_USE_BROWSER_HEADED", "PIE_COMPUTER_USE_CURSOR_OVERLAY"].includes(key)) {
|
|
4433
4441
|
const parsed = parseBoolean(value);
|
|
4434
4442
|
if (parsed === void 0) throw new Error(`Invalid ${key}`);
|
|
4435
4443
|
out[key] = String(parsed);
|
|
@@ -5384,7 +5392,7 @@ function artifactsRoot(env = process.env) {
|
|
|
5384
5392
|
init_test_backend_guard();
|
|
5385
5393
|
import { execFileSync, spawn as spawn4 } from "node:child_process";
|
|
5386
5394
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
5387
|
-
import { constants as fsConstants5, mkdirSync as mkdirSync6, mkdtempSync, readFileSync as readFileSync4, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
5395
|
+
import { constants as fsConstants5, mkdirSync as mkdirSync6, mkdtempSync, readFileSync as readFileSync4, renameSync as renameSync3, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
5388
5396
|
import { access as access4 } from "node:fs/promises";
|
|
5389
5397
|
import net2 from "node:net";
|
|
5390
5398
|
import os4 from "node:os";
|
|
@@ -6140,14 +6148,48 @@ var CdpTab = class _CdpTab {
|
|
|
6140
6148
|
this.loadFired = void 0;
|
|
6141
6149
|
}
|
|
6142
6150
|
}
|
|
6143
|
-
async
|
|
6151
|
+
async resolveVisibleBackendPoint(backendNodeId) {
|
|
6152
|
+
const resolved = await this.send("DOM.resolveNode", { backendNodeId });
|
|
6153
|
+
const objectId = resolved?.object?.objectId;
|
|
6154
|
+
if (typeof objectId !== "string") return void 0;
|
|
6155
|
+
const rectRes = await this.send("Runtime.callFunctionOn", {
|
|
6156
|
+
objectId,
|
|
6157
|
+
functionDeclaration: "function(){ this.scrollIntoView({block:'center', inline:'center'}); const r = this.getBoundingClientRect(); const vw = window.innerWidth || 0; const vh = window.innerHeight || 0; const left = Math.max(0, r.left); const top = Math.max(0, r.top); const right = Math.min(vw, r.right); const bottom = Math.min(vh, r.bottom); const w = right - left; const h = bottom - top; return w > 0 && h > 0 ? { x: left + w / 2, y: top + h / 2 } : null; }",
|
|
6158
|
+
returnByValue: true
|
|
6159
|
+
});
|
|
6160
|
+
const pt = !rectRes?.exceptionDetails ? rectRes?.result?.value : void 0;
|
|
6161
|
+
if (pt && typeof pt.x === "number" && typeof pt.y === "number" && Number.isFinite(pt.x) && Number.isFinite(pt.y)) {
|
|
6162
|
+
return { x: pt.x, y: pt.y };
|
|
6163
|
+
}
|
|
6164
|
+
return void 0;
|
|
6165
|
+
}
|
|
6166
|
+
async clickBackendNode(backendNodeId, clickCount2 = 1) {
|
|
6167
|
+
const count = Math.max(1, Math.min(3, Math.trunc(clickCount2)));
|
|
6168
|
+
if (count > 1) {
|
|
6169
|
+
const pt = await this.resolveVisibleBackendPoint(backendNodeId);
|
|
6170
|
+
if (!pt) throw new Error(`CDP could not resolve visible viewport point for backend node ${backendNodeId} multi-click.`);
|
|
6171
|
+
await this.mouseAt(pt.x, pt.y, "mouseMoved", "left", 0);
|
|
6172
|
+
for (let c = 1; c <= count; c += 1) {
|
|
6173
|
+
await this.mouseAt(pt.x, pt.y, "mousePressed", "left", c);
|
|
6174
|
+
await this.mouseAt(pt.x, pt.y, "mouseReleased", "left", c);
|
|
6175
|
+
}
|
|
6176
|
+
return;
|
|
6177
|
+
}
|
|
6144
6178
|
await this.withBackendNode(backendNodeId, "function(){ this.scrollIntoView({block:'center', inline:'center'}); this.click(); }");
|
|
6145
6179
|
}
|
|
6146
6180
|
async focusBackendNode(backendNodeId) {
|
|
6147
6181
|
await this.withBackendNode(backendNodeId, "function(){ this.scrollIntoView({block:'center', inline:'center'}); this.focus(); }");
|
|
6148
6182
|
}
|
|
6149
6183
|
async typeIntoBackendNode(backendNodeId, text, replace) {
|
|
6150
|
-
|
|
6184
|
+
if (!replace) {
|
|
6185
|
+
await this.withBackendNode(
|
|
6186
|
+
backendNodeId,
|
|
6187
|
+
"function(){ if (this.isConnected === false) throw new Error('Target element is detached.'); const ariaDisabled = typeof this.getAttribute === 'function' && this.getAttribute('aria-disabled') === 'true'; if (this.disabled || ariaDisabled || this.readOnly) throw new Error('Target element is disabled or read-only.'); const editable = ('value' in this && !this.disabled && !this.readOnly) || this.isContentEditable === true; if (!editable) throw new Error('Target element is not editable.'); if (typeof this.scrollIntoView === 'function') this.scrollIntoView({block:'center', inline:'center'}); if (typeof this.focus === 'function') this.focus(); const root = typeof this.getRootNode === 'function' ? this.getRootNode() : this.ownerDocument; const active = root && 'activeElement' in root ? root.activeElement : (this.ownerDocument ? this.ownerDocument.activeElement : null); const focused = active === this || (this.isContentEditable === true && active != null && typeof this.contains === 'function' && this.contains(active)); if (!focused) throw new Error('Target element did not accept focus; refusing to insert text into another element.'); if (this.isContentEditable === true) { const sel = this.ownerDocument && this.ownerDocument.defaultView && typeof this.ownerDocument.defaultView.getSelection === 'function' ? this.ownerDocument.defaultView.getSelection() : null; if (sel && sel.rangeCount > 0 && sel.anchorNode && typeof this.contains === 'function' && !this.contains(sel.anchorNode)) { if (this.ownerDocument && typeof this.ownerDocument.createRange === 'function') { const range = this.ownerDocument.createRange(); range.selectNodeContents(this); range.collapse(false); sel.removeAllRanges(); sel.addRange(range); } } if (sel && sel.rangeCount > 0 && sel.anchorNode && typeof this.contains === 'function' && !this.contains(sel.anchorNode)) { throw new Error('Contenteditable target does not own selection; refusing to insert text.'); } } }"
|
|
6188
|
+
);
|
|
6189
|
+
await this.send("Input.insertText", { text });
|
|
6190
|
+
return;
|
|
6191
|
+
}
|
|
6192
|
+
await this.withBackendNode(backendNodeId, "function(text){ this.scrollIntoView({block:'center', inline:'center'}); this.focus(); if ('value' in this) { const proto = Object.getPrototypeOf(this); const desc = proto && Object.getOwnPropertyDescriptor(proto, 'value'); if (desc && typeof desc.set === 'function') desc.set.call(this, text); else this.value = text; } else { this.textContent = text; } this.dispatchEvent(new InputEvent('input', {bubbles:true, inputType:'insertReplacementText', data:text})); this.dispatchEvent(new Event('change', {bubbles:true})); }", [text]);
|
|
6151
6193
|
}
|
|
6152
6194
|
async wheelAt(x, y, deltaX, deltaY) {
|
|
6153
6195
|
await this.send("Input.dispatchMouseEvent", {
|
|
@@ -6206,10 +6248,29 @@ var CdpTab = class _CdpTab {
|
|
|
6206
6248
|
}
|
|
6207
6249
|
async dragPath(path15) {
|
|
6208
6250
|
if (path15.length < 2) throw new Error("CDP drag requires at least two points.");
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6251
|
+
let pressed = false;
|
|
6252
|
+
let lastPoint = path15[0];
|
|
6253
|
+
let primaryError;
|
|
6254
|
+
try {
|
|
6255
|
+
await this.mouseAt(path15[0].x, path15[0].y, "mousePressed");
|
|
6256
|
+
pressed = true;
|
|
6257
|
+
for (const point of path15.slice(1)) {
|
|
6258
|
+
await this.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: point.x, y: point.y, button: "left", buttons: 1 });
|
|
6259
|
+
lastPoint = point;
|
|
6260
|
+
}
|
|
6261
|
+
} catch (error) {
|
|
6262
|
+
primaryError = error;
|
|
6263
|
+
throw error;
|
|
6264
|
+
} finally {
|
|
6265
|
+
if (pressed) {
|
|
6266
|
+
if (primaryError !== void 0) {
|
|
6267
|
+
await this.mouseAt(lastPoint.x, lastPoint.y, "mouseReleased").catch(() => {
|
|
6268
|
+
});
|
|
6269
|
+
} else {
|
|
6270
|
+
await this.mouseAt(lastPoint.x, lastPoint.y, "mouseReleased");
|
|
6271
|
+
}
|
|
6272
|
+
}
|
|
6273
|
+
}
|
|
6213
6274
|
}
|
|
6214
6275
|
async withBackendNode(backendNodeId, functionDeclaration, args = []) {
|
|
6215
6276
|
const resolved = await this.send("DOM.resolveNode", { backendNodeId });
|
|
@@ -6388,9 +6449,9 @@ async function listCdpPageContexts(port = getComputerUseEnvironmentValue("PIE_CO
|
|
|
6388
6449
|
url: page.url ?? ""
|
|
6389
6450
|
}));
|
|
6390
6451
|
}
|
|
6391
|
-
async function cdpClickForContext(contextId, backendNodeId) {
|
|
6452
|
+
async function cdpClickForContext(contextId, backendNodeId, clickCount2 = 1) {
|
|
6392
6453
|
return await withCdpContextTab(contextId, async (tab) => {
|
|
6393
|
-
await tab.clickBackendNode(backendNodeId);
|
|
6454
|
+
await tab.clickBackendNode(backendNodeId, clickCount2);
|
|
6394
6455
|
return true;
|
|
6395
6456
|
}) === true;
|
|
6396
6457
|
}
|
|
@@ -8254,8 +8315,33 @@ function escapeEre(value) {
|
|
|
8254
8315
|
return value.replace(/[\\^$.|?*+()[{]/g, (ch) => `\\${ch}`);
|
|
8255
8316
|
}
|
|
8256
8317
|
async function scanProfileHolders(profile) {
|
|
8257
|
-
if (process.platform === "win32")
|
|
8258
|
-
|
|
8318
|
+
if (process.platform === "win32") {
|
|
8319
|
+
return await new Promise((resolve2) => {
|
|
8320
|
+
execFile(
|
|
8321
|
+
"powershell.exe",
|
|
8322
|
+
[
|
|
8323
|
+
"-NoProfile",
|
|
8324
|
+
"-NonInteractive",
|
|
8325
|
+
"-Command",
|
|
8326
|
+
"Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -and $_.CommandLine.Contains($env:PIE_TARGET_PROFILE) } | Select-Object -ExpandProperty ProcessId"
|
|
8327
|
+
],
|
|
8328
|
+
{
|
|
8329
|
+
timeout: 3e3,
|
|
8330
|
+
windowsHide: true,
|
|
8331
|
+
env: { ...process.env, PIE_TARGET_PROFILE: profile }
|
|
8332
|
+
},
|
|
8333
|
+
(error, stdout) => {
|
|
8334
|
+
if (error) {
|
|
8335
|
+
resolve2({ kind: "unknown" });
|
|
8336
|
+
return;
|
|
8337
|
+
}
|
|
8338
|
+
const pids = String(stdout ?? "").split(/\s+/).map(Number).filter((n) => Number.isInteger(n) && n > 0 && n !== process.pid);
|
|
8339
|
+
resolve2(pids.length > 0 ? { kind: "ok", pids } : { kind: "none" });
|
|
8340
|
+
}
|
|
8341
|
+
);
|
|
8342
|
+
});
|
|
8343
|
+
}
|
|
8344
|
+
const pattern = `user-data-dir=${escapeEre(profile)}([[:space:]"']|$)`;
|
|
8259
8345
|
return await new Promise((resolve2) => {
|
|
8260
8346
|
execFile("pgrep", ["-f", pattern], { timeout: 1500 }, (error, stdout) => {
|
|
8261
8347
|
if (!error) {
|
|
@@ -8272,57 +8358,153 @@ async function scanProfileHolders(profile) {
|
|
|
8272
8358
|
});
|
|
8273
8359
|
});
|
|
8274
8360
|
}
|
|
8275
|
-
|
|
8361
|
+
function pidStillAlive(pid) {
|
|
8362
|
+
try {
|
|
8363
|
+
process.kill(pid, 0);
|
|
8364
|
+
return true;
|
|
8365
|
+
} catch (error) {
|
|
8366
|
+
return error.code === "EPERM";
|
|
8367
|
+
}
|
|
8368
|
+
}
|
|
8369
|
+
async function verifyProfileHolderDetailed(pid, profile) {
|
|
8370
|
+
if (process.platform === "win32") {
|
|
8371
|
+
return await new Promise((resolve2) => {
|
|
8372
|
+
execFile(
|
|
8373
|
+
"powershell.exe",
|
|
8374
|
+
[
|
|
8375
|
+
"-NoProfile",
|
|
8376
|
+
"-NonInteractive",
|
|
8377
|
+
"-Command",
|
|
8378
|
+
`Get-CimInstance Win32_Process -Filter "ProcessId=${pid}" | Select-Object -ExpandProperty CommandLine`
|
|
8379
|
+
],
|
|
8380
|
+
{ timeout: 2500, windowsHide: true },
|
|
8381
|
+
(error, stdout) => {
|
|
8382
|
+
if (error) {
|
|
8383
|
+
resolve2(pidStillAlive(pid) ? "unknown" : "no_match");
|
|
8384
|
+
return;
|
|
8385
|
+
}
|
|
8386
|
+
const command = String(stdout ?? "").trim();
|
|
8387
|
+
if (!command) {
|
|
8388
|
+
resolve2(pidStillAlive(pid) ? "unknown" : "no_match");
|
|
8389
|
+
return;
|
|
8390
|
+
}
|
|
8391
|
+
resolve2(commandIncludesExactUserDataDir(command, profile) ? "match" : "no_match");
|
|
8392
|
+
}
|
|
8393
|
+
);
|
|
8394
|
+
});
|
|
8395
|
+
}
|
|
8276
8396
|
if (process.platform === "darwin") {
|
|
8277
8397
|
return await new Promise((resolve2) => {
|
|
8278
8398
|
execFile("ps", ["-o", "command=", "-p", String(pid)], { timeout: 1500 }, (error, stdout) => {
|
|
8279
8399
|
if (error) {
|
|
8280
|
-
resolve2(
|
|
8400
|
+
resolve2(pidStillAlive(pid) ? "unknown" : "no_match");
|
|
8281
8401
|
return;
|
|
8282
8402
|
}
|
|
8283
8403
|
const command = String(stdout ?? "").trim();
|
|
8284
8404
|
if (!command) {
|
|
8285
|
-
resolve2(
|
|
8405
|
+
resolve2(pidStillAlive(pid) ? "unknown" : "no_match");
|
|
8286
8406
|
return;
|
|
8287
8407
|
}
|
|
8288
|
-
resolve2(commandIncludesExactUserDataDir(command, profile));
|
|
8408
|
+
resolve2(commandIncludesExactUserDataDir(command, profile) ? "match" : "no_match");
|
|
8289
8409
|
});
|
|
8290
8410
|
});
|
|
8291
8411
|
}
|
|
8292
8412
|
return await new Promise((resolve2) => {
|
|
8293
8413
|
execFile("cat", [`/proc/${pid}/cmdline`], { timeout: 1500 }, (error, stdout) => {
|
|
8294
8414
|
if (error) {
|
|
8295
|
-
resolve2(
|
|
8415
|
+
resolve2(pidStillAlive(pid) ? "unknown" : "no_match");
|
|
8296
8416
|
return;
|
|
8297
8417
|
}
|
|
8298
8418
|
const argv = String(stdout ?? "").split("\0").filter(Boolean);
|
|
8299
|
-
|
|
8419
|
+
if (argv.length === 0) {
|
|
8420
|
+
resolve2(pidStillAlive(pid) ? "unknown" : "no_match");
|
|
8421
|
+
return;
|
|
8422
|
+
}
|
|
8423
|
+
resolve2(argv.some((arg, i) => arg === `--user-data-dir=${profile}` || arg === "--user-data-dir" && argv[i + 1] === profile) ? "match" : "no_match");
|
|
8300
8424
|
});
|
|
8301
8425
|
});
|
|
8302
8426
|
}
|
|
8427
|
+
async function verifyProfileHolder(pid, profile) {
|
|
8428
|
+
return await verifyProfileHolderDetailed(pid, profile) === "match";
|
|
8429
|
+
}
|
|
8430
|
+
function tokenizeCommandLine(command) {
|
|
8431
|
+
const tokens = [];
|
|
8432
|
+
let current = "";
|
|
8433
|
+
let inToken = false;
|
|
8434
|
+
let quote = null;
|
|
8435
|
+
for (let i = 0; i < command.length; i++) {
|
|
8436
|
+
const ch = command[i];
|
|
8437
|
+
if (quote !== null) {
|
|
8438
|
+
if (ch === quote) {
|
|
8439
|
+
quote = null;
|
|
8440
|
+
} else {
|
|
8441
|
+
current += ch;
|
|
8442
|
+
}
|
|
8443
|
+
continue;
|
|
8444
|
+
}
|
|
8445
|
+
if (ch === '"' || ch === "'") {
|
|
8446
|
+
quote = ch;
|
|
8447
|
+
inToken = true;
|
|
8448
|
+
continue;
|
|
8449
|
+
}
|
|
8450
|
+
if (/\s|\0/.test(ch)) {
|
|
8451
|
+
if (inToken) {
|
|
8452
|
+
tokens.push(current);
|
|
8453
|
+
current = "";
|
|
8454
|
+
inToken = false;
|
|
8455
|
+
}
|
|
8456
|
+
continue;
|
|
8457
|
+
}
|
|
8458
|
+
current += ch;
|
|
8459
|
+
inToken = true;
|
|
8460
|
+
}
|
|
8461
|
+
if (quote !== null) return void 0;
|
|
8462
|
+
if (inToken) tokens.push(current);
|
|
8463
|
+
return tokens;
|
|
8464
|
+
}
|
|
8303
8465
|
function commandIncludesExactUserDataDir(command, profile) {
|
|
8304
|
-
const
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
|
|
8308
|
-
|
|
8309
|
-
|
|
8310
|
-
|
|
8466
|
+
const tokens = tokenizeCommandLine(command);
|
|
8467
|
+
if (!tokens) return false;
|
|
8468
|
+
const exactFlag = `--user-data-dir=${profile}`;
|
|
8469
|
+
return tokens.some((arg, i) => arg === exactFlag || arg === "--user-data-dir" && tokens[i + 1] === profile);
|
|
8470
|
+
}
|
|
8471
|
+
async function terminateVerifiedPid(pid) {
|
|
8472
|
+
if (process.platform === "win32") {
|
|
8473
|
+
await new Promise((resolve2) => {
|
|
8474
|
+
execFile("taskkill.exe", ["/PID", String(pid), "/T", "/F"], { windowsHide: true, timeout: 3e3 }, () => resolve2());
|
|
8475
|
+
});
|
|
8476
|
+
return;
|
|
8477
|
+
}
|
|
8478
|
+
try {
|
|
8479
|
+
process.kill(pid, "SIGTERM");
|
|
8480
|
+
} catch {
|
|
8481
|
+
}
|
|
8482
|
+
await new Promise((resolve2) => setTimeout(resolve2, 400));
|
|
8483
|
+
if (pidStillAlive(pid)) {
|
|
8484
|
+
try {
|
|
8485
|
+
process.kill(pid, "SIGKILL");
|
|
8486
|
+
} catch {
|
|
8311
8487
|
}
|
|
8312
|
-
|
|
8488
|
+
await new Promise((resolve2) => setTimeout(resolve2, 300));
|
|
8313
8489
|
}
|
|
8314
|
-
return false;
|
|
8315
8490
|
}
|
|
8316
8491
|
async function signalTreeOfProfile(profile, signal) {
|
|
8317
8492
|
const scan = await scanProfileHolders(profile);
|
|
8318
8493
|
if (scan.kind !== "ok") return scan.kind === "none" ? 0 : -1;
|
|
8319
8494
|
let signalled = 0;
|
|
8320
8495
|
for (const pid of scan.pids) {
|
|
8321
|
-
if (
|
|
8322
|
-
|
|
8323
|
-
|
|
8496
|
+
if (await verifyProfileHolderDetailed(pid, profile) !== "match") continue;
|
|
8497
|
+
if (process.platform === "win32") {
|
|
8498
|
+
await new Promise((resolve2) => {
|
|
8499
|
+
execFile("taskkill.exe", ["/PID", String(pid), "/T", "/F"], { windowsHide: true, timeout: 2e3 }, () => resolve2());
|
|
8500
|
+
});
|
|
8324
8501
|
signalled++;
|
|
8325
|
-
}
|
|
8502
|
+
} else {
|
|
8503
|
+
try {
|
|
8504
|
+
process.kill(pid, signal);
|
|
8505
|
+
signalled++;
|
|
8506
|
+
} catch {
|
|
8507
|
+
}
|
|
8326
8508
|
}
|
|
8327
8509
|
}
|
|
8328
8510
|
if (signalled > 0) await new Promise((resolve2) => setTimeout(resolve2, 150));
|
|
@@ -8334,7 +8516,9 @@ async function countProfileHolders(profile) {
|
|
|
8334
8516
|
if (scan.kind === "unknown") return -1;
|
|
8335
8517
|
let count = 0;
|
|
8336
8518
|
for (const pid of scan.pids) {
|
|
8337
|
-
|
|
8519
|
+
const verdict = await verifyProfileHolderDetailed(pid, profile);
|
|
8520
|
+
if (verdict === "unknown") return -1;
|
|
8521
|
+
if (verdict === "match") count++;
|
|
8338
8522
|
}
|
|
8339
8523
|
return count;
|
|
8340
8524
|
}
|
|
@@ -8364,7 +8548,7 @@ async function releaseOwnedBrowser(child, port, profile) {
|
|
|
8364
8548
|
}
|
|
8365
8549
|
}
|
|
8366
8550
|
}
|
|
8367
|
-
if (profile
|
|
8551
|
+
if (profile) {
|
|
8368
8552
|
await signalTreeOfProfile(profile, "SIGTERM");
|
|
8369
8553
|
let holders = await countProfileHolders(profile);
|
|
8370
8554
|
if (holders > 0) {
|
|
@@ -8372,7 +8556,7 @@ async function releaseOwnedBrowser(child, port, profile) {
|
|
|
8372
8556
|
holders = await countProfileHolders(profile);
|
|
8373
8557
|
}
|
|
8374
8558
|
if (holders > 0) {
|
|
8375
|
-
throw new Error(`Owned browser helpers survived
|
|
8559
|
+
throw new Error(`Owned browser helpers survived termination (${holders} pids hold ${profile}); refusing to remove the profile while processes may still write it.`);
|
|
8376
8560
|
}
|
|
8377
8561
|
if (holders < 0) {
|
|
8378
8562
|
throw new Error(`Cannot verify that no process holds ${profile} (process scan unavailable); refusing to remove the profile.`);
|
|
@@ -8700,15 +8884,26 @@ function persistRuntimeBridgeState() {
|
|
|
8700
8884
|
function managedBrowserManifestPath() {
|
|
8701
8885
|
return path13.join(stateRootDir(process.env), "managed-browser.json");
|
|
8702
8886
|
}
|
|
8703
|
-
function writeManagedBrowserManifest(entry) {
|
|
8887
|
+
function writeManagedBrowserManifest(entry, opts = {}) {
|
|
8888
|
+
const target = managedBrowserManifestPath();
|
|
8889
|
+
let tmp;
|
|
8704
8890
|
try {
|
|
8705
8891
|
if (!entry) {
|
|
8706
|
-
rmSync(
|
|
8892
|
+
rmSync(target, { force: true });
|
|
8707
8893
|
return;
|
|
8708
8894
|
}
|
|
8709
8895
|
mkdirSync6(stateRootDir(process.env), { recursive: true });
|
|
8710
|
-
|
|
8711
|
-
|
|
8896
|
+
tmp = `${target}.tmp-${process.pid}-${Date.now()}`;
|
|
8897
|
+
writeFileSync3(tmp, JSON.stringify({ ...entry, startedAt: Date.now() }), { encoding: "utf8" });
|
|
8898
|
+
renameSync3(tmp, target);
|
|
8899
|
+
} catch (error) {
|
|
8900
|
+
if (tmp) {
|
|
8901
|
+
try {
|
|
8902
|
+
rmSync(tmp, { force: true });
|
|
8903
|
+
} catch {
|
|
8904
|
+
}
|
|
8905
|
+
}
|
|
8906
|
+
if (opts.strict) throw error;
|
|
8712
8907
|
}
|
|
8713
8908
|
}
|
|
8714
8909
|
function clearManagedBrowserManifest() {
|
|
@@ -8726,7 +8921,7 @@ function killManagedBrowserFast() {
|
|
|
8726
8921
|
const profile = runtimeState.managedBrowserProfileDir;
|
|
8727
8922
|
if (profile) {
|
|
8728
8923
|
try {
|
|
8729
|
-
const out = execFileSync("pgrep", ["-f", `user-data-dir=${escapeEre(profile)}([
|
|
8924
|
+
const out = execFileSync("pgrep", ["-f", `user-data-dir=${escapeEre(profile)}([[:space:]"']|$)`], { timeout: 1500, killSignal: "SIGKILL", stdio: ["ignore", "pipe", "ignore"] });
|
|
8730
8925
|
for (const pidText of String(out).split(/\s+/)) {
|
|
8731
8926
|
const pid2 = Number(pidText);
|
|
8732
8927
|
if (Number.isInteger(pid2) && pid2 > 0 && pid2 !== process.pid) {
|
|
@@ -8755,11 +8950,23 @@ async function manifestPidIsOurBrowser(pid, profileDir) {
|
|
|
8755
8950
|
return await verifyProfileHolder(pid, profileDir);
|
|
8756
8951
|
}
|
|
8757
8952
|
async function sweepOrphanedManagedBrowser() {
|
|
8953
|
+
const manifestPath = managedBrowserManifestPath();
|
|
8954
|
+
let raw;
|
|
8955
|
+
try {
|
|
8956
|
+
raw = readFileSync4(manifestPath, "utf8");
|
|
8957
|
+
} catch (error) {
|
|
8958
|
+
if (error.code === "ENOENT") return;
|
|
8959
|
+
throw error;
|
|
8960
|
+
}
|
|
8758
8961
|
let manifest;
|
|
8759
8962
|
try {
|
|
8760
|
-
manifest = JSON.parse(
|
|
8963
|
+
manifest = JSON.parse(raw);
|
|
8761
8964
|
} catch {
|
|
8762
|
-
|
|
8965
|
+
try {
|
|
8966
|
+
renameSync3(manifestPath, `${manifestPath}.corrupt-${Date.now()}`);
|
|
8967
|
+
} catch {
|
|
8968
|
+
clearManagedBrowserManifest();
|
|
8969
|
+
}
|
|
8763
8970
|
return;
|
|
8764
8971
|
}
|
|
8765
8972
|
const profileDir = typeof manifest.profileDir === "string" ? manifest.profileDir : void 0;
|
|
@@ -8775,20 +8982,12 @@ async function sweepOrphanedManagedBrowser() {
|
|
|
8775
8982
|
clearManagedBrowserManifest();
|
|
8776
8983
|
return;
|
|
8777
8984
|
}
|
|
8778
|
-
|
|
8779
|
-
if (
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
await new Promise((resolve2) => setTimeout(resolve2, 400));
|
|
8785
|
-
if (processAlive(pid)) {
|
|
8786
|
-
try {
|
|
8787
|
-
process.kill(pid, "SIGKILL");
|
|
8788
|
-
} catch {
|
|
8789
|
-
}
|
|
8790
|
-
await new Promise((resolve2) => setTimeout(resolve2, 300));
|
|
8791
|
-
}
|
|
8985
|
+
const pidVerified = pid !== void 0 && await manifestPidIsOurBrowser(pid, resolved);
|
|
8986
|
+
if (port && pidVerified) {
|
|
8987
|
+
await requestBrowserClose(port).catch(() => void 0);
|
|
8988
|
+
}
|
|
8989
|
+
if (pidVerified && pid !== void 0) {
|
|
8990
|
+
await terminateVerifiedPid(pid);
|
|
8792
8991
|
}
|
|
8793
8992
|
await releaseOwnedBrowser(void 0, void 0, resolved);
|
|
8794
8993
|
clearManagedBrowserManifest();
|
|
@@ -9565,16 +9764,25 @@ async function helperAct(target, action, headless, signal) {
|
|
|
9565
9764
|
};
|
|
9566
9765
|
const textTimeout = "text" in action.params ? action.params.text.length * 25 + 4e3 : COMMAND_TIMEOUT_MS5;
|
|
9567
9766
|
const timeoutMs = Math.max(COMMAND_TIMEOUT_MS5, textTimeout);
|
|
9568
|
-
|
|
9767
|
+
const configuredPolicy = currentDeliveryPolicy();
|
|
9768
|
+
const forbidForeground = headless || configuredPolicy === "background" || configuredPolicy === "ax_only";
|
|
9769
|
+
if ((action.usesCurrentFocus || action.needsForeground) && !forbidForeground) {
|
|
9569
9770
|
const foreground = checked(await currentPlatformBackend.act(helperActRequest(target, action, "foreground"), { signal, timeoutMs }));
|
|
9570
9771
|
const trace = executionTraceFromAct(foreground, "foreground");
|
|
9571
9772
|
trace.backgroundFirst = false;
|
|
9572
9773
|
return trace;
|
|
9573
9774
|
}
|
|
9775
|
+
if ((action.usesCurrentFocus || action.needsForeground) && forbidForeground) {
|
|
9776
|
+
const err = new Error(
|
|
9777
|
+
`Action '${action.action}' requires foreground focus/HID input, which is blocked under '${headless ? "headless" : configuredPolicy}' background-only policy. Use a semantic ref/CDP action or explicitly opt into PIE_COMPUTER_USE_DELIVERY_POLICY=foreground.`
|
|
9778
|
+
);
|
|
9779
|
+
err.code = "foreground_required";
|
|
9780
|
+
throw err;
|
|
9781
|
+
}
|
|
9574
9782
|
try {
|
|
9575
|
-
const initialPolicy = headless ? "ax_only" : "background";
|
|
9783
|
+
const initialPolicy = headless || configuredPolicy === "ax_only" ? "ax_only" : "background";
|
|
9576
9784
|
const result = checked(await currentPlatformBackend.act(helperActRequest(target, action, initialPolicy), { signal, timeoutMs }));
|
|
9577
|
-
if (canRetryInForeground(action, result.outcome, headless)) {
|
|
9785
|
+
if (!forbidForeground && canRetryInForeground(action, result.outcome, headless)) {
|
|
9578
9786
|
const foreground = checked(await currentPlatformBackend.act(helperActRequest(target, action, "foreground"), { signal, timeoutMs }));
|
|
9579
9787
|
const trace2 = executionTraceFromAct(foreground, "foreground");
|
|
9580
9788
|
trace2.backgroundFirst = true;
|
|
@@ -9588,7 +9796,7 @@ async function helperAct(target, action, headless, signal) {
|
|
|
9588
9796
|
return trace;
|
|
9589
9797
|
} catch (error) {
|
|
9590
9798
|
const code = error?.code;
|
|
9591
|
-
if (code !== "foreground_required" ||
|
|
9799
|
+
if (code !== "foreground_required" || forbidForeground) throw error;
|
|
9592
9800
|
const foreground = checked(await currentPlatformBackend.act(helperActRequest(target, action, "foreground"), { signal, timeoutMs }));
|
|
9593
9801
|
const trace = executionTraceFromAct(foreground, "foreground");
|
|
9594
9802
|
trace.backgroundFirst = true;
|
|
@@ -10368,8 +10576,7 @@ async function performBrowserTransaction(params, actions, signal) {
|
|
|
10368
10576
|
for (const { action, target } of prepared) {
|
|
10369
10577
|
let worked = false;
|
|
10370
10578
|
if (action.action === "press" || action.action === "click" && action.ref) {
|
|
10371
|
-
worked =
|
|
10372
|
-
for (let count = 0; count < (action.clickCount ?? 1); count += 1) worked = await cdpClickForContext(contextId, target.backendNodeId) && worked;
|
|
10579
|
+
worked = await cdpClickForContext(contextId, target.backendNodeId, action.clickCount ?? 1);
|
|
10373
10580
|
} else if (action.action === "click") {
|
|
10374
10581
|
worked = await cdpMouseForContext(contextId, action.x, action.y, "mousePressed", action.button ?? "left", action.clickCount ?? 1) && await cdpMouseForContext(contextId, action.x, action.y, "mouseReleased", action.button ?? "left", action.clickCount ?? 1);
|
|
10375
10582
|
} else if (action.action === "setText") worked = await cdpTypeForContext(contextId, target.backendNodeId, action.text ?? "", true);
|
|
@@ -10501,21 +10708,43 @@ async function performLaunchBrowser(params, signal) {
|
|
|
10501
10708
|
const url = requestedUrl ?? "about:blank";
|
|
10502
10709
|
await disconnectCdp();
|
|
10503
10710
|
await releaseOwnedBrowserState(runtimeState);
|
|
10711
|
+
await sweepOrphanedManagedBrowser();
|
|
10504
10712
|
const profileDir = mkdtempSync(path13.join(os4.tmpdir(), `pie-${browser}-cdp-`));
|
|
10713
|
+
try {
|
|
10714
|
+
writeManagedBrowserManifest({ port: String(port), profileDir }, { strict: true });
|
|
10715
|
+
} catch (error) {
|
|
10716
|
+
try {
|
|
10717
|
+
rmSync(profileDir, { recursive: true, force: true });
|
|
10718
|
+
} catch {
|
|
10719
|
+
}
|
|
10720
|
+
throw error;
|
|
10721
|
+
}
|
|
10722
|
+
const browserHeaded = getComputerUseEnvironmentValue("PIE_COMPUTER_USE_BROWSER_HEADED") === "true";
|
|
10505
10723
|
const args = [
|
|
10506
10724
|
`--remote-debugging-port=${port}`,
|
|
10507
10725
|
`--user-data-dir=${profileDir}`,
|
|
10508
10726
|
"--no-first-run",
|
|
10509
10727
|
"--no-default-browser-check",
|
|
10728
|
+
...!browserHeaded ? ["--headless=new", "--window-size=1440,900"] : [],
|
|
10510
10729
|
url
|
|
10511
10730
|
];
|
|
10512
|
-
|
|
10731
|
+
let managedBrowser;
|
|
10732
|
+
try {
|
|
10733
|
+
managedBrowser = spawn4(executable, args, { stdio: "ignore", detached: true, windowsHide: !browserHeaded });
|
|
10734
|
+
} catch (error) {
|
|
10735
|
+
clearManagedBrowserManifest();
|
|
10736
|
+
try {
|
|
10737
|
+
rmSync(profileDir, { recursive: true, force: true });
|
|
10738
|
+
} catch {
|
|
10739
|
+
}
|
|
10740
|
+
throw error;
|
|
10741
|
+
}
|
|
10513
10742
|
managedBrowser.unref();
|
|
10514
10743
|
runtimeState.managedBrowser = managedBrowser;
|
|
10515
10744
|
runtimeState.managedBrowserCdpPort = String(port);
|
|
10516
10745
|
runtimeState.managedBrowserPid = managedBrowser.pid;
|
|
10517
10746
|
runtimeState.managedBrowserProfileDir = profileDir;
|
|
10518
|
-
writeManagedBrowserManifest({ pid: managedBrowser.pid, port: String(port), profileDir });
|
|
10747
|
+
writeManagedBrowserManifest({ ...managedBrowser.pid !== void 0 ? { pid: managedBrowser.pid } : {}, port: String(port), profileDir });
|
|
10519
10748
|
persistRuntimeBridgeState();
|
|
10520
10749
|
setManagedCdpPort(String(port));
|
|
10521
10750
|
try {
|