@opencode/browse 0.0.14 → 0.0.15-dev.102
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/dist/{cli-yfb0tpey.mjs → cli-9sgczzrw.mjs} +15 -15
- package/dist/cli.mjs +25 -19
- package/dist/{helpers-wmv2w09f.mjs → helpers-18tnh8f3.mjs} +3 -1
- package/dist/{main-tazq9tx0.mjs → main-0jyyvzkx.mjs} +2 -2
- package/dist/{main-4y53y07g.mjs → main-0wvv6nat.mjs} +23 -7
- package/dist/{main-c1pcfhv0.mjs → main-2rtwhyhh.mjs} +2 -2
- package/dist/{main-8a0bd051.mjs → main-80jesay1.mjs} +11 -4
- package/dist/{main-6d4whs59.mjs → main-8r1t7vba.mjs} +1 -1
- package/dist/main-aeg6a5nk.mjs +4 -0
- package/dist/main-ckssvk4c.mjs +18 -0
- package/dist/{main-k9w11hc3.mjs → main-ezf20xwm.mjs} +1 -1
- package/dist/{main-6a3ja0sq.mjs → main-f7qkgyz5.mjs} +30 -15
- package/dist/{main-brfzdj0f.mjs → main-qxer7zjj.mjs} +2 -2
- package/dist/{main-pyvdynkn.mjs → main-rz1540v9.mjs} +2 -2
- package/dist/{mcp-cv3ka7f7.mjs → mcp-rmj6h1s1.mjs} +6 -6
- package/dist/{migrate-6bw83m5v.mjs → migrate-xgnfe9c3.mjs} +10 -13
- package/dist/{relay-6h6vhd11.mjs → relay-5zw323v4.mjs} +499 -173
- package/dist/{runtime-update-xrak66a4.mjs → runtime-update-wn4gab74.mjs} +4 -4
- package/dist/{setup-y7z0dmhf.mjs → setup-6fa9eddq.mjs} +30 -11
- package/dist/{skill-text-mrxy6zpc.mjs → skill-text-v68nbc12.mjs} +20 -5
- package/dist/{supervisor-1y9j1tpk.mjs → supervisor-rce413ez.mjs} +3 -3
- package/dist/{update-cw10gp3w.mjs → update-g0qt4kea.mjs} +3 -3
- package/dist/{version-p978a2bv.mjs → version-kpv6469c.mjs} +1 -1
- package/package.json +1 -1
- package/skills/browse/SKILL.md +20 -5
- package/dist/main-pk9kkfhn.mjs +0 -4
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
opencodeBrowserVersion2,
|
|
3
3
|
opencodeBrowserBuildId2
|
|
4
|
-
} from "./main-
|
|
4
|
+
} from "./main-aeg6a5nk.mjs";
|
|
5
5
|
import {
|
|
6
|
+
defaultRoots,
|
|
7
|
+
configRoot2,
|
|
6
8
|
dataRoot,
|
|
7
9
|
stateRoot,
|
|
10
|
+
cacheRoot,
|
|
11
|
+
installedBinaryPath,
|
|
12
|
+
installerBinaryPath,
|
|
8
13
|
oldStoreMarker,
|
|
9
14
|
fromCheckout,
|
|
10
15
|
cliCommand,
|
|
@@ -20,7 +25,7 @@ import {
|
|
|
20
25
|
setStoredMode,
|
|
21
26
|
autoUpdateStatus,
|
|
22
27
|
createAutoUpdater
|
|
23
|
-
} from "./main-
|
|
28
|
+
} from "./main-0wvv6nat.mjs";
|
|
24
29
|
import {
|
|
25
30
|
extensionProtocolVersion,
|
|
26
31
|
minExtensionProtocolVersion,
|
|
@@ -88,6 +93,7 @@ import {
|
|
|
88
93
|
sendCdpEvent2,
|
|
89
94
|
getObject2,
|
|
90
95
|
getString2,
|
|
96
|
+
createTargetUrl2,
|
|
91
97
|
getNumber2,
|
|
92
98
|
getIdText2,
|
|
93
99
|
headerValue2,
|
|
@@ -95,7 +101,7 @@ import {
|
|
|
95
101
|
isRestrictedTarget2,
|
|
96
102
|
isRestrictedUrl2,
|
|
97
103
|
dataUrlDocument2
|
|
98
|
-
} from "./main-
|
|
104
|
+
} from "./main-80jesay1.mjs";
|
|
99
105
|
import {
|
|
100
106
|
context,
|
|
101
107
|
pendingPairingCodeKeys,
|
|
@@ -113,7 +119,7 @@ import {
|
|
|
113
119
|
pairingSessionKey,
|
|
114
120
|
sessionProof,
|
|
115
121
|
wrapToken
|
|
116
|
-
} from "./main-
|
|
122
|
+
} from "./main-8r1t7vba.mjs";
|
|
117
123
|
import {
|
|
118
124
|
makeUnsafe,
|
|
119
125
|
SettingsInputError,
|
|
@@ -141,22 +147,25 @@ import {
|
|
|
141
147
|
checkNavigationUrl,
|
|
142
148
|
readSecret,
|
|
143
149
|
secretText
|
|
144
|
-
} from "./main-
|
|
150
|
+
} from "./main-rz1540v9.mjs";
|
|
145
151
|
import {
|
|
146
152
|
defaultJournalBaseDir,
|
|
147
153
|
makeJournalEntry,
|
|
148
154
|
appendJournalEntry,
|
|
149
155
|
startJournalRetention
|
|
150
|
-
} from "./main-
|
|
156
|
+
} from "./main-0jyyvzkx.mjs";
|
|
151
157
|
import {
|
|
152
158
|
createUpdateWatcher2
|
|
153
|
-
} from "./main-
|
|
159
|
+
} from "./main-qxer7zjj.mjs";
|
|
154
160
|
import {
|
|
155
161
|
relayHostname,
|
|
156
162
|
isLocalPeer,
|
|
157
163
|
installedDevExtension,
|
|
158
164
|
syncDevExtension
|
|
159
|
-
} from "./main-
|
|
165
|
+
} from "./main-2rtwhyhh.mjs";
|
|
166
|
+
import {
|
|
167
|
+
legacyRoots
|
|
168
|
+
} from "./main-ckssvk4c.mjs";
|
|
160
169
|
import {
|
|
161
170
|
currentTimeMillis,
|
|
162
171
|
value,
|
|
@@ -210,6 +219,7 @@ import {
|
|
|
210
219
|
asVoid2,
|
|
211
220
|
catch_,
|
|
212
221
|
catchCause,
|
|
222
|
+
catchIf,
|
|
213
223
|
mapError,
|
|
214
224
|
tapError,
|
|
215
225
|
retry,
|
|
@@ -268,7 +278,7 @@ import {
|
|
|
268
278
|
relayToken,
|
|
269
279
|
secretsEqual,
|
|
270
280
|
ensurePrivateDirectory
|
|
271
|
-
} from "./main-
|
|
281
|
+
} from "./main-ezf20xwm.mjs";
|
|
272
282
|
import {
|
|
273
283
|
isString,
|
|
274
284
|
isNumber,
|
|
@@ -2288,7 +2298,7 @@ function challengeWarning(outcome) {
|
|
|
2288
2298
|
// src/execute-realm.ts
|
|
2289
2299
|
import buffer2 from "node:buffer";
|
|
2290
2300
|
import crypto5 from "node:crypto";
|
|
2291
|
-
import
|
|
2301
|
+
import util4 from "node:util";
|
|
2292
2302
|
import vm3 from "node:vm";
|
|
2293
2303
|
|
|
2294
2304
|
// src/execute-realm/file-roots.ts
|
|
@@ -2393,9 +2403,12 @@ function executeFileRoots() {
|
|
|
2393
2403
|
const roots = [os2.tmpdir(), ...process.platform === "win32" ? [] : ["/tmp"], ...extra];
|
|
2394
2404
|
return [...new Set(roots.map(realpathOrSelf))];
|
|
2395
2405
|
}
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2406
|
+
var pathFlavor = (platform) => platform === "win32" ? path2.win32 : path2.posix;
|
|
2407
|
+
var foldCase = (value, platform) => platform === "win32" || platform === "darwin" ? value.toLowerCase() : value;
|
|
2408
|
+
function isInside(child, parent, platform = process.platform) {
|
|
2409
|
+
const paths = pathFlavor(platform);
|
|
2410
|
+
const relative = paths.relative(foldCase(parent, platform), foldCase(child, platform));
|
|
2411
|
+
return relative === "" || !paths.isAbsolute(relative) && relative !== ".." && !relative.startsWith(`..${paths.sep}`);
|
|
2399
2412
|
}
|
|
2400
2413
|
function realTarget(target) {
|
|
2401
2414
|
let current = path2.resolve(target);
|
|
@@ -2416,6 +2429,39 @@ function realTarget(target) {
|
|
|
2416
2429
|
class ExecuteFileAccessError extends Error {
|
|
2417
2430
|
name = "ExecuteFileAccessError";
|
|
2418
2431
|
}
|
|
2432
|
+
function browseDirectories() {
|
|
2433
|
+
return [...new Set([
|
|
2434
|
+
configRoot2(),
|
|
2435
|
+
dataRoot(),
|
|
2436
|
+
stateRoot(),
|
|
2437
|
+
cacheRoot(),
|
|
2438
|
+
...Object.values(defaultRoots()),
|
|
2439
|
+
...legacyRoots()
|
|
2440
|
+
])];
|
|
2441
|
+
}
|
|
2442
|
+
function isInstallSibling(target, binary, platform = process.platform) {
|
|
2443
|
+
const paths = pathFlavor(platform);
|
|
2444
|
+
const folder = foldCase(paths.dirname(binary), platform);
|
|
2445
|
+
const relative = paths.relative(folder, foldCase(target, platform));
|
|
2446
|
+
if (relative === "" || paths.isAbsolute(relative))
|
|
2447
|
+
return false;
|
|
2448
|
+
const [first] = relative.split(paths.sep);
|
|
2449
|
+
const name = foldCase(paths.basename(binary), platform);
|
|
2450
|
+
if (!first?.startsWith(`${name}.`))
|
|
2451
|
+
return false;
|
|
2452
|
+
const staged = first.slice(name.length + 1);
|
|
2453
|
+
return staged === "new" || staged.startsWith("old-") || staged.startsWith("migrate-") || /^\d+\.new$/.test(staged);
|
|
2454
|
+
}
|
|
2455
|
+
function isBinaryOrStaging(target, binary, platform) {
|
|
2456
|
+
const resolved = realTarget(binary);
|
|
2457
|
+
const stagedAt = path2.join(realTarget(path2.dirname(binary)), path2.basename(binary));
|
|
2458
|
+
return isInside(target, resolved, platform) || isInside(target, stagedAt, platform) || isInstallSibling(target, resolved, platform) || isInstallSibling(target, stagedAt, platform);
|
|
2459
|
+
}
|
|
2460
|
+
function isBrowseOwned(target, platform = process.platform) {
|
|
2461
|
+
if (browseDirectories().some((root) => isInside(target, realTarget(root), platform)))
|
|
2462
|
+
return true;
|
|
2463
|
+
return [installedBinaryPath(), installerBinaryPath()].some((binary) => isBinaryOrStaging(target, binary, platform));
|
|
2464
|
+
}
|
|
2419
2465
|
function assertExecuteFilePath(target, operation) {
|
|
2420
2466
|
if (typeof target !== "string" || target.length === 0) {
|
|
2421
2467
|
throw new ExecuteFileAccessError(`${operation}: file paths must be non-empty strings`);
|
|
@@ -2426,9 +2472,8 @@ function assertExecuteFilePath(target, operation) {
|
|
|
2426
2472
|
throw new ExecuteFileAccessError(`${operation}: use an absolute path inside ${describeRoots()}, for example files.path("name.png")`);
|
|
2427
2473
|
}
|
|
2428
2474
|
const resolved = realTarget(target);
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
throw new ExecuteFileAccessError(`${operation}: ${target} is inside browse's data directory, which execute code cannot access`);
|
|
2475
|
+
if (isBrowseOwned(resolved)) {
|
|
2476
|
+
throw new ExecuteFileAccessError(`${operation}: ${target} is inside browse's own files, which execute code cannot access`);
|
|
2432
2477
|
}
|
|
2433
2478
|
if (!roots.some((root) => isInside(resolved, root))) {
|
|
2434
2479
|
throw new ExecuteFileAccessError(`${operation}: ${target} is outside the execute file roots ${describeRoots()}. Set ${allowNodeEnvironmentVariable}=1 for unrestricted file access.`);
|
|
@@ -2668,12 +2713,68 @@ import inspector from "node:inspector";
|
|
|
2668
2713
|
import module from "node:module";
|
|
2669
2714
|
import net from "node:net";
|
|
2670
2715
|
import os3 from "node:os";
|
|
2716
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2671
2717
|
import tls from "node:tls";
|
|
2672
|
-
import
|
|
2718
|
+
import util3 from "node:util";
|
|
2673
2719
|
import v8 from "node:v8";
|
|
2674
2720
|
import vm from "node:vm";
|
|
2675
2721
|
import workerThreads from "node:worker_threads";
|
|
2676
2722
|
import * as acorn from "acorn";
|
|
2723
|
+
|
|
2724
|
+
// src/execute-realm/rejection-text.ts
|
|
2725
|
+
import util2 from "node:util";
|
|
2726
|
+
var placeholder = "reason not shown";
|
|
2727
|
+
var nativeStackGetter = Object.getOwnPropertyDescriptor(new Error, "stack")?.get;
|
|
2728
|
+
function safeErrorMessage(value, maxLength = 300) {
|
|
2729
|
+
if (typeof value === "string")
|
|
2730
|
+
return value.length > 0 ? value.slice(0, maxLength) : placeholder;
|
|
2731
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || typeof value === "symbol") {
|
|
2732
|
+
return String(value).slice(0, maxLength);
|
|
2733
|
+
}
|
|
2734
|
+
if (!isSafeNativeError(value))
|
|
2735
|
+
return placeholder;
|
|
2736
|
+
const message = ownDataProperty(value, "message");
|
|
2737
|
+
return typeof message === "string" && message.length > 0 ? message.slice(0, maxLength) : placeholder;
|
|
2738
|
+
}
|
|
2739
|
+
function safeErrorStack(value) {
|
|
2740
|
+
if (!isSafeHostError(value))
|
|
2741
|
+
return;
|
|
2742
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, "stack");
|
|
2743
|
+
if (descriptor === undefined)
|
|
2744
|
+
return;
|
|
2745
|
+
if ("value" in descriptor)
|
|
2746
|
+
return typeof descriptor.value === "string" ? descriptor.value : undefined;
|
|
2747
|
+
if (descriptor.get === undefined || descriptor.get !== nativeStackGetter)
|
|
2748
|
+
return;
|
|
2749
|
+
try {
|
|
2750
|
+
const stack = descriptor.get.call(value);
|
|
2751
|
+
return typeof stack === "string" ? stack : undefined;
|
|
2752
|
+
} catch {
|
|
2753
|
+
return;
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
function isSafeNativeError(value) {
|
|
2757
|
+
return typeof value === "object" && value !== null && !util2.types.isProxy(value) && util2.types.isNativeError(value);
|
|
2758
|
+
}
|
|
2759
|
+
function isSafeHostError(value) {
|
|
2760
|
+
if (!isSafeNativeError(value))
|
|
2761
|
+
return false;
|
|
2762
|
+
let prototype = Object.getPrototypeOf(value);
|
|
2763
|
+
for (let depth = 0;prototype !== null && depth < 32; depth += 1) {
|
|
2764
|
+
if (prototype === Error.prototype)
|
|
2765
|
+
return true;
|
|
2766
|
+
if (util2.types.isProxy(prototype))
|
|
2767
|
+
return false;
|
|
2768
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
2769
|
+
}
|
|
2770
|
+
return false;
|
|
2771
|
+
}
|
|
2772
|
+
function ownDataProperty(value, key) {
|
|
2773
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
2774
|
+
return descriptor !== undefined && "value" in descriptor ? descriptor.value : undefined;
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2777
|
+
// src/execute-realm/membrane-policy.ts
|
|
2677
2778
|
var deniedHostValues = new Map([
|
|
2678
2779
|
[process, "process"],
|
|
2679
2780
|
[globalThis, "the relay's global object"],
|
|
@@ -2697,9 +2798,9 @@ var deniedHostValues = new Map([
|
|
|
2697
2798
|
[workerThreads, "worker_threads"],
|
|
2698
2799
|
[globalThis.fetch, "Node fetch"],
|
|
2699
2800
|
[eval, "eval"],
|
|
2700
|
-
[
|
|
2701
|
-
[
|
|
2702
|
-
[
|
|
2801
|
+
[util3.inspect, "host object inspection"],
|
|
2802
|
+
[util3.format, "host object formatting"],
|
|
2803
|
+
[util3.formatWithOptions, "host object formatting"],
|
|
2703
2804
|
[crypto4.setEngine, "loading native crypto engines"],
|
|
2704
2805
|
[events2.setMaxListeners, "changing shared event-emitter defaults or prototypes"],
|
|
2705
2806
|
...[crypto4.pbkdf2Sync, crypto4.scryptSync, crypto4.hkdfSync, crypto4.generateKeyPairSync, crypto4.generateKeySync, crypto4.generatePrimeSync, crypto4.checkPrimeSync].map((fn) => [fn, `crypto.${fn.name} (blocks the relay; use the async version)`])
|
|
@@ -2805,56 +2906,111 @@ function isObjectLike(value) {
|
|
|
2805
2906
|
return typeof value === "object" && value !== null || typeof value === "function";
|
|
2806
2907
|
}
|
|
2807
2908
|
var isHiddenKey = (key) => typeof key === "string" && key.startsWith("_");
|
|
2808
|
-
var
|
|
2809
|
-
var
|
|
2909
|
+
var activeOwner;
|
|
2910
|
+
var rejectionContext = new AsyncLocalStorage;
|
|
2911
|
+
var promiseOwners = new WeakMap;
|
|
2810
2912
|
var stopPromiseHook;
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2913
|
+
var promiseHookUsers = 0;
|
|
2914
|
+
function enterRejectionOwner(owner) {
|
|
2915
|
+
const previous = activeOwner;
|
|
2916
|
+
activeOwner = owner;
|
|
2917
|
+
return () => {
|
|
2918
|
+
activeOwner = previous;
|
|
2919
|
+
};
|
|
2920
|
+
}
|
|
2921
|
+
function runWithRejectionOwner(owner, run) {
|
|
2922
|
+
return rejectionContext.run(owner, () => {
|
|
2923
|
+
const restore = enterRejectionOwner(owner);
|
|
2924
|
+
try {
|
|
2925
|
+
return run();
|
|
2926
|
+
} finally {
|
|
2927
|
+
restore();
|
|
2928
|
+
}
|
|
2929
|
+
});
|
|
2930
|
+
}
|
|
2931
|
+
function retainPromiseHook() {
|
|
2932
|
+
promiseHookUsers += 1;
|
|
2933
|
+
if (promiseHookUsers === 1) {
|
|
2934
|
+
stopPromiseHook = v8.promiseHooks.createHook({ init(promise, parent) {
|
|
2935
|
+
const owner = activeOwner ?? rejectionContext.getStore() ?? (parent ? promiseOwners.get(parent) : undefined);
|
|
2936
|
+
if (owner)
|
|
2937
|
+
promiseOwners.set(promise, owner);
|
|
2826
2938
|
} });
|
|
2827
2939
|
}
|
|
2940
|
+
let released = false;
|
|
2828
2941
|
return () => {
|
|
2829
|
-
|
|
2830
|
-
|
|
2942
|
+
if (released)
|
|
2943
|
+
return;
|
|
2944
|
+
released = true;
|
|
2945
|
+
promiseHookUsers -= 1;
|
|
2946
|
+
if (promiseHookUsers === 0 && stopPromiseHook) {
|
|
2831
2947
|
stopPromiseHook();
|
|
2832
2948
|
stopPromiseHook = undefined;
|
|
2833
2949
|
}
|
|
2834
2950
|
};
|
|
2835
2951
|
}
|
|
2952
|
+
function trackPromisesOf(owner) {
|
|
2953
|
+
const restoreOwner = enterRejectionOwner(owner);
|
|
2954
|
+
if (process.versions.bun) {
|
|
2955
|
+
const entered = { owner, at: Date.now() };
|
|
2956
|
+
lastOwner = entered;
|
|
2957
|
+
return () => {
|
|
2958
|
+
restoreOwner();
|
|
2959
|
+
entered.at = Date.now();
|
|
2960
|
+
};
|
|
2961
|
+
}
|
|
2962
|
+
const releaseHook = retainPromiseHook();
|
|
2963
|
+
return () => {
|
|
2964
|
+
restoreOwner();
|
|
2965
|
+
releaseHook();
|
|
2966
|
+
};
|
|
2967
|
+
}
|
|
2836
2968
|
var realmsByPromisePrototype = new WeakMap;
|
|
2837
|
-
var
|
|
2838
|
-
var
|
|
2969
|
+
var lastOwner;
|
|
2970
|
+
var lastOwnerWindowMs = 1000;
|
|
2839
2971
|
function registerRealmPromisePrototype(prototype, realm) {
|
|
2840
2972
|
if (process.versions.bun)
|
|
2841
2973
|
realmsByPromisePrototype.set(prototype, realm);
|
|
2842
2974
|
}
|
|
2843
|
-
function
|
|
2844
|
-
|
|
2845
|
-
if (byPrototype)
|
|
2846
|
-
return byPrototype;
|
|
2847
|
-
if (!lastRealm || lastRealm.realm.isStopped)
|
|
2975
|
+
function bunRejectionOwner(promise) {
|
|
2976
|
+
if (!lastOwner || lastOwner.owner.isStopped)
|
|
2848
2977
|
return;
|
|
2849
|
-
return
|
|
2978
|
+
return activeOwner === lastOwner.owner || Date.now() - lastOwner.at <= lastOwnerWindowMs ? lastOwner.owner : undefined;
|
|
2850
2979
|
}
|
|
2851
|
-
function handleExecuteRealmRejection(promise) {
|
|
2852
|
-
const
|
|
2853
|
-
|
|
2980
|
+
function handleExecuteRealmRejection(promise, reason) {
|
|
2981
|
+
const byPrototype = process.versions.bun ? realmsByPromisePrototype.get(Object.getPrototypeOf(promise)) : undefined;
|
|
2982
|
+
const exact = promiseOwners.get(promise) ?? byPrototype;
|
|
2983
|
+
const owner = exact ?? (process.versions.bun ? bunRejectionOwner(promise) : undefined);
|
|
2984
|
+
if (!owner)
|
|
2854
2985
|
return false;
|
|
2855
|
-
|
|
2986
|
+
owner.handleUnhandledRejection(reason, exact !== undefined);
|
|
2856
2987
|
return true;
|
|
2857
2988
|
}
|
|
2989
|
+
function unhandledExecuteRejectionWarning(detail, certain) {
|
|
2990
|
+
if (!certain) {
|
|
2991
|
+
return "Execute code may have started a promise that rejected and was never awaited. The rejection was contained and the relay kept running; await the promise or handle its rejection to return the error from execute.";
|
|
2992
|
+
}
|
|
2993
|
+
return `Execute code started a promise that rejected and was never awaited: ${detail}. The rejection was contained and the relay kept running; await the promise or handle its rejection to return the error from execute.`;
|
|
2994
|
+
}
|
|
2995
|
+
function handleRealmUnhandledRejection(realm, cause, certain, warn, pending) {
|
|
2996
|
+
if (realm.isStopped)
|
|
2997
|
+
return;
|
|
2998
|
+
const description = certain ? rejectionDescription(realm, cause) : "a rejected promise";
|
|
2999
|
+
if (!pending) {
|
|
3000
|
+
try {
|
|
3001
|
+
warn?.(unhandledExecuteRejectionWarning(description, certain));
|
|
3002
|
+
} catch {}
|
|
3003
|
+
}
|
|
3004
|
+
realm.dispose(new Error(`Unhandled execute rejection: ${description}; JavaScript state will reset before the next execute`));
|
|
3005
|
+
}
|
|
3006
|
+
function rejectionDescription(realm, cause) {
|
|
3007
|
+
if (isObjectLike(cause)) {
|
|
3008
|
+
const host = realm.hostValueForSandboxValue(cause);
|
|
3009
|
+
if (host !== undefined)
|
|
3010
|
+
return safeErrorMessage(host);
|
|
3011
|
+
}
|
|
3012
|
+
return safeErrorMessage(cause);
|
|
3013
|
+
}
|
|
2858
3014
|
var thrownByRealm = new WeakMap;
|
|
2859
3015
|
function tagThrownByRealm(value, realm) {
|
|
2860
3016
|
if (!thrownByRealm.has(value))
|
|
@@ -2987,11 +3143,13 @@ class ExecuteRealm {
|
|
|
2987
3143
|
entryScript;
|
|
2988
3144
|
global;
|
|
2989
3145
|
onHostCall;
|
|
3146
|
+
onUnhandledRejection;
|
|
2990
3147
|
refuseDynamicImport = () => {
|
|
2991
3148
|
throw new this.SandboxError("import() is not available in execute code");
|
|
2992
3149
|
};
|
|
2993
3150
|
constructor(options = {}) {
|
|
2994
3151
|
this.onHostCall = options.onHostCall;
|
|
3152
|
+
this.onUnhandledRejection = options.onUnhandledRejection;
|
|
2995
3153
|
const importModuleDynamically = this.refuseDynamicImport;
|
|
2996
3154
|
const dontContextify = vm3.constants?.DONT_CONTEXTIFY;
|
|
2997
3155
|
this.context = vm3.createContext(dontContextify ?? Object.create(null), {
|
|
@@ -3036,6 +3194,12 @@ class ExecuteRealm {
|
|
|
3036
3194
|
get isStopped() {
|
|
3037
3195
|
return this.stopped !== undefined;
|
|
3038
3196
|
}
|
|
3197
|
+
handleUnhandledRejection(cause, certain) {
|
|
3198
|
+
handleRealmUnhandledRejection(this, cause, certain, this.onUnhandledRejection, this.pendingRuns.size > 0);
|
|
3199
|
+
}
|
|
3200
|
+
hostValueForSandboxValue(value) {
|
|
3201
|
+
return isObjectLike(value) ? this.hostBySandboxProxy.get(value) : undefined;
|
|
3202
|
+
}
|
|
3039
3203
|
enter(entry) {
|
|
3040
3204
|
if (this.stopped)
|
|
3041
3205
|
throw this.stopped;
|
|
@@ -3154,7 +3318,7 @@ class ExecuteRealm {
|
|
|
3154
3318
|
throw this.sandboxError(`${denied} is not available in execute code. Set ${allowNodeEnvironmentVariable}=1 for full Node access.`);
|
|
3155
3319
|
if (this.isSandboxNative(value))
|
|
3156
3320
|
return value;
|
|
3157
|
-
if (
|
|
3321
|
+
if (util4.types.isPromise(value))
|
|
3158
3322
|
return this.toSandboxPromise(value);
|
|
3159
3323
|
if (Buffer.isBuffer(value)) {
|
|
3160
3324
|
const copy = Buffer.alloc(value.length);
|
|
@@ -3163,11 +3327,11 @@ class ExecuteRealm {
|
|
|
3163
3327
|
this.sandboxProxyByHost.set(value, proxy);
|
|
3164
3328
|
return proxy;
|
|
3165
3329
|
}
|
|
3166
|
-
if (
|
|
3330
|
+
if (util4.types.isArrayBuffer(value)) {
|
|
3167
3331
|
const SandboxUint8Array = this.sandboxIntrinsics.Uint8Array;
|
|
3168
3332
|
return new SandboxUint8Array(new Uint8Array(value)).buffer;
|
|
3169
3333
|
}
|
|
3170
|
-
if (
|
|
3334
|
+
if (util4.types.isTypedArray(value) && !Buffer.isBuffer(value)) {
|
|
3171
3335
|
const name = Object.prototype.toString.call(value).slice(8, -1);
|
|
3172
3336
|
const Constructor = this.sandboxIntrinsics[name] ?? this.sandboxIntrinsics.Uint8Array;
|
|
3173
3337
|
return new Constructor(value);
|
|
@@ -3177,7 +3341,7 @@ class ExecuteRealm {
|
|
|
3177
3341
|
throw this.sandboxError(deniedClass);
|
|
3178
3342
|
if (!this.forceProxy.has(value) && typeof value === "object") {
|
|
3179
3343
|
const prototype = Reflect.getPrototypeOf(value);
|
|
3180
|
-
if (Array.isArray(value) && prototype === Array.prototype ||
|
|
3344
|
+
if (Array.isArray(value) && prototype === Array.prototype || util4.types.isArgumentsObject(value)) {
|
|
3181
3345
|
const output = [];
|
|
3182
3346
|
Reflect.setPrototypeOf(output, this.sandboxArrayPrototype);
|
|
3183
3347
|
seen.set(value, output);
|
|
@@ -3186,7 +3350,7 @@ class ExecuteRealm {
|
|
|
3186
3350
|
output[index] = this.toSandbox(array[index], seen);
|
|
3187
3351
|
return output;
|
|
3188
3352
|
}
|
|
3189
|
-
if ((prototype === Object.prototype || prototype === null) && !Object.hasOwn(value, "constructor") && !
|
|
3353
|
+
if ((prototype === Object.prototype || prototype === null) && !Object.hasOwn(value, "constructor") && !util4.types.isProxy(value)) {
|
|
3190
3354
|
const output = Object.create(prototype === null ? null : this.sandboxObjectPrototype);
|
|
3191
3355
|
seen.set(value, output);
|
|
3192
3356
|
for (const key of Object.keys(value)) {
|
|
@@ -3438,16 +3602,16 @@ class ExecuteRealm {
|
|
|
3438
3602
|
}
|
|
3439
3603
|
}
|
|
3440
3604
|
copyToHost(value, seen) {
|
|
3441
|
-
if (
|
|
3605
|
+
if (util4.types.isPromise(value))
|
|
3442
3606
|
return this.toHostPromise(value);
|
|
3443
|
-
if (
|
|
3607
|
+
if (util4.types.isDate(value))
|
|
3444
3608
|
return new Date(Date.prototype.getTime.call(value));
|
|
3445
|
-
if (
|
|
3609
|
+
if (util4.types.isRegExp(value)) {
|
|
3446
3610
|
const source = Reflect.get(value, "source");
|
|
3447
3611
|
const flags = Reflect.get(value, "flags");
|
|
3448
3612
|
return new RegExp(String(source), String(flags));
|
|
3449
3613
|
}
|
|
3450
|
-
if (
|
|
3614
|
+
if (util4.types.isNativeError(value) || value instanceof this.SandboxError) {
|
|
3451
3615
|
const name = String(Reflect.get(value, "name") ?? "Error");
|
|
3452
3616
|
const output = new Error(String(Reflect.get(value, "message") ?? ""));
|
|
3453
3617
|
seen.set(value, output);
|
|
@@ -3465,26 +3629,26 @@ class ExecuteRealm {
|
|
|
3465
3629
|
Object.defineProperty(output, "cause", { value: this.toHost(cause, seen), configurable: true, writable: true });
|
|
3466
3630
|
return output;
|
|
3467
3631
|
}
|
|
3468
|
-
if (
|
|
3632
|
+
if (util4.types.isMap(value)) {
|
|
3469
3633
|
const output = new Map;
|
|
3470
3634
|
seen.set(value, output);
|
|
3471
3635
|
Map.prototype.forEach.call(value, (item, key) => output.set(this.toHost(key, seen), this.toHost(item, seen)));
|
|
3472
3636
|
return output;
|
|
3473
3637
|
}
|
|
3474
|
-
if (
|
|
3638
|
+
if (util4.types.isSet(value)) {
|
|
3475
3639
|
const output = new Set;
|
|
3476
3640
|
seen.set(value, output);
|
|
3477
3641
|
Set.prototype.forEach.call(value, (item) => output.add(this.toHost(item, seen)));
|
|
3478
3642
|
return output;
|
|
3479
3643
|
}
|
|
3480
|
-
if (
|
|
3644
|
+
if (util4.types.isArrayBuffer(value))
|
|
3481
3645
|
return new Uint8Array(new Uint8Array(value)).buffer;
|
|
3482
|
-
if (
|
|
3646
|
+
if (util4.types.isTypedArray(value)) {
|
|
3483
3647
|
const name = Object.prototype.toString.call(value).slice(8, -1);
|
|
3484
3648
|
const Constructor = globalThis[name] ?? Uint8Array;
|
|
3485
3649
|
return new Constructor(value);
|
|
3486
3650
|
}
|
|
3487
|
-
if (Array.isArray(value) ||
|
|
3651
|
+
if (Array.isArray(value) || util4.types.isArgumentsObject(value)) {
|
|
3488
3652
|
const output = [];
|
|
3489
3653
|
seen.set(value, output);
|
|
3490
3654
|
const array = value;
|
|
@@ -3615,6 +3779,45 @@ import https2 from "node:https";
|
|
|
3615
3779
|
import os4 from "node:os";
|
|
3616
3780
|
import * as acorn2 from "acorn";
|
|
3617
3781
|
|
|
3782
|
+
// src/execute/rejection-scope.ts
|
|
3783
|
+
var defaultRejectionOwnershipExpiryMs = 10 * 60000;
|
|
3784
|
+
|
|
3785
|
+
class ExecuteRejectionScope {
|
|
3786
|
+
releaseHook;
|
|
3787
|
+
expiry;
|
|
3788
|
+
expiryMs;
|
|
3789
|
+
onRejection;
|
|
3790
|
+
constructor(options = {}) {
|
|
3791
|
+
this.onRejection = options.onRejection;
|
|
3792
|
+
this.expiryMs = options.expiryMs ?? defaultRejectionOwnershipExpiryMs;
|
|
3793
|
+
}
|
|
3794
|
+
begin() {
|
|
3795
|
+
if (process.versions.bun || this.releaseHook)
|
|
3796
|
+
return;
|
|
3797
|
+
this.releaseHook = retainPromiseHook();
|
|
3798
|
+
this.expiry = setTimeout(() => this.end(), this.expiryMs);
|
|
3799
|
+
this.expiry.unref?.();
|
|
3800
|
+
}
|
|
3801
|
+
invoke(run) {
|
|
3802
|
+
if (process.versions.bun)
|
|
3803
|
+
return run();
|
|
3804
|
+
return runWithRejectionOwner(this, run);
|
|
3805
|
+
}
|
|
3806
|
+
end() {
|
|
3807
|
+
if (this.expiry !== undefined) {
|
|
3808
|
+
clearTimeout(this.expiry);
|
|
3809
|
+
this.expiry = undefined;
|
|
3810
|
+
}
|
|
3811
|
+
this.releaseHook?.();
|
|
3812
|
+
this.releaseHook = undefined;
|
|
3813
|
+
}
|
|
3814
|
+
handleUnhandledRejection(cause, certain) {
|
|
3815
|
+
try {
|
|
3816
|
+
this.onRejection?.(unhandledExecuteRejectionWarning(safeErrorMessage(cause), certain));
|
|
3817
|
+
} catch {}
|
|
3818
|
+
}
|
|
3819
|
+
}
|
|
3820
|
+
|
|
3618
3821
|
// src/execute/console.ts
|
|
3619
3822
|
var sessions = new WeakMap;
|
|
3620
3823
|
var listeners = new WeakMap;
|
|
@@ -3675,7 +3878,7 @@ function describe(arg) {
|
|
|
3675
3878
|
}
|
|
3676
3879
|
|
|
3677
3880
|
// src/execute/log-capture.ts
|
|
3678
|
-
import
|
|
3881
|
+
import util5 from "node:util";
|
|
3679
3882
|
var maxCapturedPageLogs = 50;
|
|
3680
3883
|
var maxCapturedScriptLogs = 100;
|
|
3681
3884
|
function createExecuteLogCapture(limits = {}) {
|
|
@@ -3864,7 +4067,7 @@ function formatLogValue(value) {
|
|
|
3864
4067
|
if (isString(value)) {
|
|
3865
4068
|
return value;
|
|
3866
4069
|
}
|
|
3867
|
-
return
|
|
4070
|
+
return util5.inspect(value, { depth: 4, colors: false, maxArrayLength: 100, maxStringLength: 1000 });
|
|
3868
4071
|
}
|
|
3869
4072
|
|
|
3870
4073
|
// src/execute/target-selection.ts
|
|
@@ -3982,6 +4185,8 @@ var defaultHandoffTimeoutMs = 10 * 60 * 1000;
|
|
|
3982
4185
|
var defaultHandoffMessage = "Complete the requested task, then use the in-page continue control.";
|
|
3983
4186
|
var timedOut = Symbol("timed-out");
|
|
3984
4187
|
var defaultPageClosedWarning = "The session default page was closed; created a new page. References to the old page in state are stale.";
|
|
4188
|
+
var debuggingBarDismissedWarning = "The user dismissed the browser's debugging bar (Cancel/OK), which disconnects browse from every tab. Browse no longer controls the session's page; tabs an agent opened stay open until idle cleanup closes them. To use a tab the user lent, ask them to lend it again with the browse toolbar button.";
|
|
4189
|
+
var debuggingBarDismissedStop = "The user dismissed the browser's debugging bar (Cancel/OK) while this script ran, which disconnects browse from every tab, so it was stopped. The tab may still be open but browse no longer controls it. Run execute again to continue in a new tab; to use a tab the user lent, ask them to lend it again with the browse toolbar button.";
|
|
3985
4190
|
var defaultPageRecoveredWarning = "The session default page was unresponsive; created a new page. References to the old page in state are stale.";
|
|
3986
4191
|
var defaultPageCrashedWarning = "The session default page target crashed; checking it before the next execute.";
|
|
3987
4192
|
var defaultPageRepairedWarning = "The session default page stopped answering automation; browse reconnected and re-resolved the same tab. References to the old page in state are stale.";
|
|
@@ -4369,7 +4574,7 @@ var sandboxGlobalKeys = [
|
|
|
4369
4574
|
"pageConsole",
|
|
4370
4575
|
"secrets"
|
|
4371
4576
|
];
|
|
4372
|
-
async function runUserCode({ code, globals, realm }) {
|
|
4577
|
+
async function runUserCode({ code, globals, realm, onUnhandledRejection }) {
|
|
4373
4578
|
const logCapture = createExecuteLogCapture();
|
|
4374
4579
|
const navigations = [];
|
|
4375
4580
|
const onConsole = (message) => {
|
|
@@ -4432,8 +4637,14 @@ ${wrapCodeWithModuleAliases(code, Object.keys(sandboxModules))}
|
|
|
4432
4637
|
const AsyncFunction = async function() {}.constructor;
|
|
4433
4638
|
const fn = new AsyncFunction("console", ...sandboxGlobalKeys, `${wrapCodeWithModuleAliases(code, Object.keys(nodeModules))}
|
|
4434
4639
|
//# sourceURL=${executeFilename}`);
|
|
4435
|
-
const
|
|
4436
|
-
|
|
4640
|
+
const scope = process.versions.bun || !onUnhandledRejection ? undefined : new ExecuteRejectionScope({ onRejection: onUnhandledRejection });
|
|
4641
|
+
scope?.begin();
|
|
4642
|
+
try {
|
|
4643
|
+
const result = await (scope ? scope.invoke(() => fn(...values)) : fn(...values));
|
|
4644
|
+
return { result, ...buildResultMetadata() };
|
|
4645
|
+
} finally {
|
|
4646
|
+
scope?.end();
|
|
4647
|
+
}
|
|
4437
4648
|
} catch (cause) {
|
|
4438
4649
|
const error = cause instanceof Error ? cause : new Error("execute sandbox code", { cause });
|
|
4439
4650
|
const metadata = buildResultMetadata();
|
|
@@ -4605,6 +4816,7 @@ class DefaultPageHost {
|
|
|
4605
4816
|
pendingTargetRebind;
|
|
4606
4817
|
lastKnownNonBlankUrl;
|
|
4607
4818
|
recreatedFromClosedUrl;
|
|
4819
|
+
pageReleasedByDebuggingBar = false;
|
|
4608
4820
|
explicitMediaFeatures = new Map;
|
|
4609
4821
|
explicitMedia;
|
|
4610
4822
|
pendingWarnings = [];
|
|
@@ -4648,15 +4860,18 @@ class DefaultPageHost {
|
|
|
4648
4860
|
this.pageProtectedUi = protectedUi;
|
|
4649
4861
|
return true;
|
|
4650
4862
|
}
|
|
4651
|
-
markTargetDetached(targetId) {
|
|
4863
|
+
markTargetDetached(targetId, options = {}) {
|
|
4652
4864
|
if (this.defaultPageTargetId !== targetId) {
|
|
4653
4865
|
return false;
|
|
4654
4866
|
}
|
|
4655
|
-
|
|
4867
|
+
const releasedByUser = options.releasedByUser === true;
|
|
4868
|
+
if (releasedByUser)
|
|
4869
|
+
this.recreatedFromClosedUrl = undefined;
|
|
4870
|
+
else if (this.lastKnownNonBlankUrl)
|
|
4656
4871
|
this.recreatedFromClosedUrl = this.lastKnownNonBlankUrl;
|
|
4657
|
-
|
|
4872
|
+
this.pageReleasedByDebuggingBar = releasedByUser;
|
|
4658
4873
|
this.unbindDefaultPage(undefined);
|
|
4659
|
-
this.addWarningOnce(defaultPageClosedWarning);
|
|
4874
|
+
this.addWarningOnce(releasedByUser ? debuggingBarDismissedWarning : defaultPageClosedWarning);
|
|
4660
4875
|
return true;
|
|
4661
4876
|
}
|
|
4662
4877
|
markTargetReplaced(previousTargetId, targetId) {
|
|
@@ -4693,6 +4908,7 @@ class DefaultPageHost {
|
|
|
4693
4908
|
this.defaultPageTargetId = targetId;
|
|
4694
4909
|
this.ownsPage = ownsPage;
|
|
4695
4910
|
this.pendingTargetRebind = undefined;
|
|
4911
|
+
this.pageReleasedByDebuggingBar = false;
|
|
4696
4912
|
this.recordNonBlankUrl(safePageUrl(page));
|
|
4697
4913
|
const close = () => {
|
|
4698
4914
|
if (this.page !== page)
|
|
@@ -4801,6 +5017,10 @@ class DefaultPageHost {
|
|
|
4801
5017
|
});
|
|
4802
5018
|
this.pendingWarnings.push(defaultPageClosedWarning);
|
|
4803
5019
|
}
|
|
5020
|
+
if (this.pageReleasedByDebuggingBar) {
|
|
5021
|
+
this.pageReleasedByDebuggingBar = false;
|
|
5022
|
+
this.addWarningOnce(debuggingBarDismissedWarning);
|
|
5023
|
+
}
|
|
4804
5024
|
const page = await context.newPage();
|
|
4805
5025
|
const targetId = await resolvePageTargetId(page);
|
|
4806
5026
|
this.bindDefaultPage(page, targetId, true, true);
|
|
@@ -4847,7 +5067,7 @@ class DefaultPageHost {
|
|
|
4847
5067
|
}
|
|
4848
5068
|
|
|
4849
5069
|
// src/execute/result-formatting.ts
|
|
4850
|
-
import
|
|
5070
|
+
import util6 from "node:util";
|
|
4851
5071
|
var maxExecuteResultChars = 1e5;
|
|
4852
5072
|
function boundExecuteResult(text, value, hasValue) {
|
|
4853
5073
|
const valueChars = hasValue && value !== null && typeof value === "object" ? safeJsonStringify(value)?.length ?? 0 : typeof value === "string" ? value.length : 0;
|
|
@@ -4869,7 +5089,7 @@ function stringifyResult(result) {
|
|
|
4869
5089
|
if (result === undefined) {
|
|
4870
5090
|
return "undefined";
|
|
4871
5091
|
}
|
|
4872
|
-
return
|
|
5092
|
+
return util6.inspect(result, { depth: 3, colors: false, maxArrayLength: 50, maxStringLength: 4000 });
|
|
4873
5093
|
}
|
|
4874
5094
|
var maxJsonSafeDepth = 8;
|
|
4875
5095
|
var maxJsonSafeBytes = 32 * 1024;
|
|
@@ -9859,7 +10079,8 @@ class ExecuteSandbox extends DefaultPageHost {
|
|
|
9859
10079
|
return new ExecuteRealm({
|
|
9860
10080
|
onHostCall: (fn, receiver, args) => {
|
|
9861
10081
|
this.addWarningOnce(pageVisibleApiWarning(fn, receiver, args));
|
|
9862
|
-
}
|
|
10082
|
+
},
|
|
10083
|
+
onUnhandledRejection: (warning) => this.addWarningOnce(warning)
|
|
9863
10084
|
});
|
|
9864
10085
|
}
|
|
9865
10086
|
execute(code, options = {}) {
|
|
@@ -9874,7 +10095,12 @@ class ExecuteSandbox extends DefaultPageHost {
|
|
|
9874
10095
|
for (const warning of pageVisibleApiSourceWarnings(code))
|
|
9875
10096
|
this.addWarningOnce(warning);
|
|
9876
10097
|
const globals = await this.getGlobals(options);
|
|
9877
|
-
const { result, logs, logSummary, aftermath } = await runUserCode({
|
|
10098
|
+
const { result, logs, logSummary, aftermath } = await runUserCode({
|
|
10099
|
+
code,
|
|
10100
|
+
globals,
|
|
10101
|
+
...this.realm ? { realm: this.realm } : {},
|
|
10102
|
+
onUnhandledRejection: (warning) => this.addWarningOnce(warning)
|
|
10103
|
+
}).then(async (completed) => ({ ...completed, aftermath: await this.withChallenge(globals.page, completed.aftermath, false) })).catch(async (error) => {
|
|
9878
10104
|
if (!(error instanceof ExecuteCodeError) || !error.aftermath)
|
|
9879
10105
|
throw error;
|
|
9880
10106
|
throw new ExecuteCodeError(error.originalError, error.logs, error.logSummary, await this.withChallenge(globals.page, error.aftermath, true));
|
|
@@ -12185,9 +12411,9 @@ class OpenCodeBrowserSessions {
|
|
|
12185
12411
|
markTargetProtectedUi(targetId, protectedUi) {
|
|
12186
12412
|
return this.collectSessionIds((session) => session.sandbox.markTargetProtectedUi(targetId, protectedUi));
|
|
12187
12413
|
}
|
|
12188
|
-
markTargetDetached(targetId) {
|
|
12414
|
+
markTargetDetached(targetId, options = {}) {
|
|
12189
12415
|
return this.collectSessionIds((session) => {
|
|
12190
|
-
const detached = session.sandbox.markTargetDetached(targetId);
|
|
12416
|
+
const detached = session.sandbox.markTargetDetached(targetId, options);
|
|
12191
12417
|
if (session.target?.id === targetId && session.target.owner === "user") {
|
|
12192
12418
|
this.notifyTargetOwnershipChange(this.targetOwnership.releaseTargetOwnership(targetId, session.id));
|
|
12193
12419
|
}
|
|
@@ -14621,28 +14847,56 @@ function replayTargetCreated(options) {
|
|
|
14621
14847
|
}
|
|
14622
14848
|
}
|
|
14623
14849
|
|
|
14624
|
-
// src/relay/
|
|
14625
|
-
|
|
14626
|
-
|
|
14627
|
-
|
|
14628
|
-
|
|
14629
|
-
|
|
14630
|
-
|
|
14631
|
-
|
|
14632
|
-
|
|
14633
|
-
|
|
14850
|
+
// src/relay/data-navigation.ts
|
|
14851
|
+
var navigateTopFrameToDataUrl = fnUntraced(function* (options) {
|
|
14852
|
+
const url = getString2(options.params, "url")?.trim();
|
|
14853
|
+
if (!url || !/^data:/i.test(url))
|
|
14854
|
+
return;
|
|
14855
|
+
const { tabId, mainFrameIdsByTab, blankNavigationWaiters, registry, sendDebuggerCommand } = options;
|
|
14856
|
+
const frameId = mainFrameIdsByTab.get(tabId) ?? registry.tabTargets.get(tabId)?.targetInfo.targetId;
|
|
14857
|
+
const requestedFrameId = getString2(options.params, "frameId");
|
|
14858
|
+
if (!frameId || requestedFrameId !== undefined && requestedFrameId !== frameId || blankNavigationWaiters.has(tabId))
|
|
14859
|
+
return;
|
|
14860
|
+
const html = yield* tryPromise(() => dataUrlDocument2(url)).pipe(orElseSucceed(() => {
|
|
14861
|
+
return;
|
|
14862
|
+
}));
|
|
14863
|
+
if (html === undefined)
|
|
14864
|
+
return;
|
|
14865
|
+
const committedLoaders = new Set;
|
|
14866
|
+
let loaderCommitted = () => {};
|
|
14867
|
+
blankNavigationWaiters.set(tabId, (frameUrl, loaderId) => {
|
|
14868
|
+
if (frameUrl !== "about:blank" || loaderId === undefined)
|
|
14634
14869
|
return;
|
|
14635
|
-
|
|
14636
|
-
|
|
14637
|
-
process.on("uncaughtException", onUncaughtException);
|
|
14638
|
-
process.on("unhandledRejection", onUnhandledRejection);
|
|
14639
|
-
return { onUncaughtException, onUnhandledRejection };
|
|
14640
|
-
}), (handlers) => {
|
|
14641
|
-
return sync2(() => {
|
|
14642
|
-
process.off("uncaughtException", handlers.onUncaughtException);
|
|
14643
|
-
process.off("unhandledRejection", handlers.onUnhandledRejection);
|
|
14870
|
+
committedLoaders.add(loaderId);
|
|
14871
|
+
loaderCommitted(loaderId);
|
|
14644
14872
|
});
|
|
14873
|
+
return yield* gen(function* () {
|
|
14874
|
+
const navigated = yield* sendDebuggerCommand({ tabId, method: "Page.navigate", params: { url: "about:blank", frameId } });
|
|
14875
|
+
const loaderId = getString2(navigated, "loaderId");
|
|
14876
|
+
if (getString2(navigated, "errorText") || loaderId === undefined)
|
|
14877
|
+
return navigated;
|
|
14878
|
+
if (!committedLoaders.has(loaderId)) {
|
|
14879
|
+
const committed = yield* promise(() => new Promise((resolve) => {
|
|
14880
|
+
loaderCommitted = (id) => {
|
|
14881
|
+
if (id === loaderId)
|
|
14882
|
+
resolve();
|
|
14883
|
+
};
|
|
14884
|
+
})).pipe(timeoutOption(1e4));
|
|
14885
|
+
if (committed._tag === "None")
|
|
14886
|
+
return navigated;
|
|
14887
|
+
}
|
|
14888
|
+
yield* sendDebuggerCommand({ tabId, method: "Page.setDocumentContent", params: { frameId, html } });
|
|
14889
|
+
relayLog("navigate.data", { tabId, chars: html.length });
|
|
14890
|
+
return { frameId: getString2(navigated, "frameId") ?? frameId, loaderId };
|
|
14891
|
+
}).pipe(ensuring(sync2(() => {
|
|
14892
|
+
blankNavigationWaiters.delete(tabId);
|
|
14893
|
+
})));
|
|
14645
14894
|
});
|
|
14895
|
+
|
|
14896
|
+
// src/relay/process-guard.ts
|
|
14897
|
+
import http4 from "node:http";
|
|
14898
|
+
|
|
14899
|
+
// src/relay/process-faults.ts
|
|
14646
14900
|
var suppressedProcessFaults = { count: 0 };
|
|
14647
14901
|
function relayProcessFaultSummary() {
|
|
14648
14902
|
return {
|
|
@@ -14654,21 +14908,25 @@ function relayProcessFaultSummary() {
|
|
|
14654
14908
|
function shouldSuppressRelayProcessFault(cause) {
|
|
14655
14909
|
if (isPatchrightProtocolError(cause))
|
|
14656
14910
|
return true;
|
|
14657
|
-
const errorText =
|
|
14658
|
-
${cause
|
|
14911
|
+
const errorText = `${safeErrorMessage(cause)}
|
|
14912
|
+
${safeErrorStack(cause) ?? ""}`;
|
|
14659
14913
|
return /playwright-core|patchright-core|coreBundle|Duplicate target/i.test(errorText);
|
|
14660
14914
|
}
|
|
14661
14915
|
function isPatchrightProtocolError(cause) {
|
|
14662
|
-
|
|
14916
|
+
if (!isSafeHostError(cause))
|
|
14917
|
+
return false;
|
|
14918
|
+
const type = Object.getOwnPropertyDescriptor(cause, "type")?.value;
|
|
14919
|
+
return Object.getOwnPropertyDescriptor(cause, "method") !== undefined && Object.getOwnPropertyDescriptor(cause, "logs") !== undefined && (type === "error" || type === "closed" || type === "crashed");
|
|
14663
14920
|
}
|
|
14664
14921
|
function isBenignClosedSessionRejection(cause) {
|
|
14665
|
-
if (!(cause
|
|
14922
|
+
if (!isSafeHostError(cause))
|
|
14666
14923
|
return false;
|
|
14667
|
-
if (!isPatchrightProtocolError(cause) && !/patchright-core|playwright-core|coreBundle/.test(cause
|
|
14924
|
+
if (!isPatchrightProtocolError(cause) && !/patchright-core|playwright-core|coreBundle/.test(safeErrorStack(cause) ?? ""))
|
|
14668
14925
|
return false;
|
|
14669
|
-
return /^Protocol error \([\w.]+\): .*(session closed|Target closed|Extension disconnected|extension is not connected|Unknown CDP session|Detached while handling command|Relay closed)/i.test(cause
|
|
14926
|
+
return /^Protocol error \([\w.]+\): .*(session closed|Target closed|Extension disconnected|extension is not connected|Unknown CDP session|Detached while handling command|Relay closed)/i.test(safeErrorMessage(cause));
|
|
14670
14927
|
}
|
|
14671
14928
|
var benignRejections = { count: 0, logged: 0, lastLogAt: 0 };
|
|
14929
|
+
var unattributedRejections = { count: 0, logged: 0, lastLogAt: 0 };
|
|
14672
14930
|
function handleRelayProcessFault(kind, cause, detail, options = {}) {
|
|
14673
14931
|
if (kind === "unhandledRejection" && isBenignClosedSessionRejection(cause)) {
|
|
14674
14932
|
benignRejections.count += 1;
|
|
@@ -14677,31 +14935,46 @@ function handleRelayProcessFault(kind, cause, detail, options = {}) {
|
|
|
14677
14935
|
const since = benignRejections.count - benignRejections.logged;
|
|
14678
14936
|
benignRejections.lastLogAt = now;
|
|
14679
14937
|
benignRejections.logged = benignRejections.count;
|
|
14680
|
-
relayLog("process.benignRejections", { count: since, total: benignRejections.count, example: cause.
|
|
14938
|
+
relayLog("process.benignRejections", { count: since, total: benignRejections.count, example: safeErrorMessage(cause).slice(0, 160) });
|
|
14681
14939
|
}
|
|
14682
14940
|
return;
|
|
14683
14941
|
}
|
|
14684
14942
|
if (shouldSuppressRelayProcessFault(cause)) {
|
|
14685
14943
|
suppressedProcessFaults.count += 1;
|
|
14686
14944
|
suppressedProcessFaults.lastAt = new Date().toISOString();
|
|
14687
|
-
suppressedProcessFaults.lastMessage = (cause
|
|
14945
|
+
suppressedProcessFaults.lastMessage = safeErrorMessage(cause).slice(0, 300);
|
|
14688
14946
|
logProcessFault(kind, cause, detail, "keeping relay alive");
|
|
14689
14947
|
return;
|
|
14690
14948
|
}
|
|
14949
|
+
if (kind === "unhandledRejection") {
|
|
14950
|
+
const description = safeErrorMessage(cause);
|
|
14951
|
+
suppressedProcessFaults.count += 1;
|
|
14952
|
+
suppressedProcessFaults.lastAt = new Date().toISOString();
|
|
14953
|
+
suppressedProcessFaults.lastMessage = description.slice(0, 300);
|
|
14954
|
+
unattributedRejections.count += 1;
|
|
14955
|
+
const now = Date.now();
|
|
14956
|
+
if (description !== unattributedRejections.lastMessage || now - unattributedRejections.lastLogAt >= 60000) {
|
|
14957
|
+
const since = unattributedRejections.count - unattributedRejections.logged;
|
|
14958
|
+
unattributedRejections.lastLogAt = now;
|
|
14959
|
+
unattributedRejections.logged = unattributedRejections.count;
|
|
14960
|
+
unattributedRejections.lastMessage = description;
|
|
14961
|
+
logProcessFault(kind, cause, { suppressed: since }, "keeping relay alive; an unhandled rejection never stops the relay");
|
|
14962
|
+
}
|
|
14963
|
+
return;
|
|
14964
|
+
}
|
|
14691
14965
|
logProcessFault(kind, cause, detail, "not a known Playwright dispatch fault; rethrowing");
|
|
14692
14966
|
const rethrow = options.rethrow ?? rethrowProcessFault;
|
|
14693
14967
|
rethrow(cause);
|
|
14694
14968
|
}
|
|
14695
14969
|
function rethrowProcessFault(cause) {
|
|
14696
|
-
if (cause
|
|
14970
|
+
if (isSafeHostError(cause)) {
|
|
14697
14971
|
throw cause;
|
|
14698
14972
|
}
|
|
14699
|
-
throw new Error(
|
|
14973
|
+
throw new Error(safeErrorMessage(cause));
|
|
14700
14974
|
}
|
|
14701
14975
|
function logProcessFault(kind, cause, detail, disposition) {
|
|
14702
|
-
const errorText = cause instanceof Error ? cause.stack ?? cause.message : String(cause);
|
|
14703
14976
|
const message = `[browse relay] ${kind}; ${disposition}
|
|
14704
|
-
${
|
|
14977
|
+
${safeErrorStack(cause) ?? safeErrorMessage(cause)}`;
|
|
14705
14978
|
console.error(message);
|
|
14706
14979
|
if (process.env.OPENCODE_BROWSER_MANAGED_RELAY === "1")
|
|
14707
14980
|
appendManagedRelayProcessLog(message);
|
|
@@ -14712,6 +14985,30 @@ ${errorText}`;
|
|
|
14712
14985
|
function debugEnvironmentEnabled(value) {
|
|
14713
14986
|
return value !== undefined && ["1", "true", "yes", "on"].includes(value.toLowerCase());
|
|
14714
14987
|
}
|
|
14988
|
+
|
|
14989
|
+
// src/relay/process-guard.ts
|
|
14990
|
+
var installRelayProcessGuard = acquireRelease(sync2(() => {
|
|
14991
|
+
const onUncaughtException = (error, origin) => {
|
|
14992
|
+
if (handleExecuteRealmException(error))
|
|
14993
|
+
return;
|
|
14994
|
+
handleRelayProcessFault("uncaughtException", error, { origin });
|
|
14995
|
+
};
|
|
14996
|
+
const onUnhandledRejection = (reason, promise) => {
|
|
14997
|
+
if (handleExecuteRealmRejection(promise, reason)) {
|
|
14998
|
+
relayLog("process.executeRejection");
|
|
14999
|
+
return;
|
|
15000
|
+
}
|
|
15001
|
+
handleRelayProcessFault("unhandledRejection", reason, {});
|
|
15002
|
+
};
|
|
15003
|
+
process.on("uncaughtException", onUncaughtException);
|
|
15004
|
+
process.on("unhandledRejection", onUnhandledRejection);
|
|
15005
|
+
return { onUncaughtException, onUnhandledRejection };
|
|
15006
|
+
}), (handlers) => {
|
|
15007
|
+
return sync2(() => {
|
|
15008
|
+
process.off("uncaughtException", handlers.onUncaughtException);
|
|
15009
|
+
process.off("unhandledRejection", handlers.onUnhandledRejection);
|
|
15010
|
+
});
|
|
15011
|
+
});
|
|
14715
15012
|
function processAlive2(pid) {
|
|
14716
15013
|
try {
|
|
14717
15014
|
process.kill(pid, 0);
|
|
@@ -14812,49 +15109,6 @@ function createCdpDispatcher(options) {
|
|
|
14812
15109
|
});
|
|
14813
15110
|
return raceFirst(sendDebuggerCommand(command), nudges);
|
|
14814
15111
|
}
|
|
14815
|
-
const navigateTopFrameToDataUrl = fnUntraced(function* (tabId, params) {
|
|
14816
|
-
const url = getString2(params, "url")?.trim();
|
|
14817
|
-
if (!url || !/^data:/i.test(url))
|
|
14818
|
-
return;
|
|
14819
|
-
const frameId = mainFrameIdsByTab.get(tabId) ?? registry.tabTargets.get(tabId)?.targetInfo.targetId;
|
|
14820
|
-
const requestedFrameId = getString2(params, "frameId");
|
|
14821
|
-
if (!frameId || requestedFrameId !== undefined && requestedFrameId !== frameId || blankNavigationWaiters.has(tabId))
|
|
14822
|
-
return;
|
|
14823
|
-
const html = yield* tryPromise(() => dataUrlDocument2(url)).pipe(orElseSucceed(() => {
|
|
14824
|
-
return;
|
|
14825
|
-
}));
|
|
14826
|
-
if (html === undefined)
|
|
14827
|
-
return;
|
|
14828
|
-
const committedLoaders = new Set;
|
|
14829
|
-
let loaderCommitted = () => {};
|
|
14830
|
-
blankNavigationWaiters.set(tabId, (frameUrl, loaderId) => {
|
|
14831
|
-
if (frameUrl !== "about:blank" || loaderId === undefined)
|
|
14832
|
-
return;
|
|
14833
|
-
committedLoaders.add(loaderId);
|
|
14834
|
-
loaderCommitted(loaderId);
|
|
14835
|
-
});
|
|
14836
|
-
return yield* gen(function* () {
|
|
14837
|
-
const navigated = yield* sendDebuggerCommand({ tabId, method: "Page.navigate", params: { url: "about:blank", frameId } });
|
|
14838
|
-
const loaderId = getString2(navigated, "loaderId");
|
|
14839
|
-
if (getString2(navigated, "errorText") || loaderId === undefined)
|
|
14840
|
-
return navigated;
|
|
14841
|
-
if (!committedLoaders.has(loaderId)) {
|
|
14842
|
-
const committed = yield* promise(() => new Promise((resolve) => {
|
|
14843
|
-
loaderCommitted = (id) => {
|
|
14844
|
-
if (id === loaderId)
|
|
14845
|
-
resolve();
|
|
14846
|
-
};
|
|
14847
|
-
})).pipe(timeoutOption(1e4));
|
|
14848
|
-
if (committed._tag === "None")
|
|
14849
|
-
return navigated;
|
|
14850
|
-
}
|
|
14851
|
-
yield* sendDebuggerCommand({ tabId, method: "Page.setDocumentContent", params: { frameId, html } });
|
|
14852
|
-
relayLog("navigate.data", { tabId, chars: html.length });
|
|
14853
|
-
return { frameId: getString2(navigated, "frameId") ?? frameId, loaderId };
|
|
14854
|
-
}).pipe(ensuring(sync2(() => {
|
|
14855
|
-
blankNavigationWaiters.delete(tabId);
|
|
14856
|
-
})));
|
|
14857
|
-
});
|
|
14858
15112
|
const routeCdpCommand = fn("Relay.routeCdpCommand")(function* (socket, message) {
|
|
14859
15113
|
const clientOpenCodeBrowserSessionId = cdpClients.sessionId(socket);
|
|
14860
15114
|
if (!shutdownControl.accepting && (!cdpClients.isSandbox(socket) || !clientOpenCodeBrowserSessionId || !sessions.hasPendingWork(clientOpenCodeBrowserSessionId))) {
|
|
@@ -14958,7 +15212,7 @@ function createCdpDispatcher(options) {
|
|
|
14958
15212
|
}
|
|
14959
15213
|
if (message.method === "Target.createTarget" || message.method === "Target.closeTarget") {
|
|
14960
15214
|
if (message.method === "Target.createTarget") {
|
|
14961
|
-
const url =
|
|
15215
|
+
const url = createTargetUrl2(message.params);
|
|
14962
15216
|
const opencodeBrowserSessionId = cdpClients.sessionId(socket);
|
|
14963
15217
|
const autoAttachParams = cdpClients.autoAttachParams(socket);
|
|
14964
15218
|
const target = yield* createAndAttachTab({
|
|
@@ -15002,7 +15256,14 @@ function createCdpDispatcher(options) {
|
|
|
15002
15256
|
if (message.method === ghostCursorCommandMethod)
|
|
15003
15257
|
return yield* ghostCursor.command(tabId, message.params);
|
|
15004
15258
|
if (message.method === "Page.navigate" && route.chromeSessionId === undefined) {
|
|
15005
|
-
const dataNavigation = yield* navigateTopFrameToDataUrl(
|
|
15259
|
+
const dataNavigation = yield* navigateTopFrameToDataUrl({
|
|
15260
|
+
tabId,
|
|
15261
|
+
params: message.params,
|
|
15262
|
+
mainFrameIdsByTab,
|
|
15263
|
+
blankNavigationWaiters,
|
|
15264
|
+
registry,
|
|
15265
|
+
sendDebuggerCommand
|
|
15266
|
+
});
|
|
15006
15267
|
if (dataNavigation)
|
|
15007
15268
|
return dataNavigation;
|
|
15008
15269
|
}
|
|
@@ -15140,6 +15401,7 @@ function createExtensionEventHandler(options) {
|
|
|
15140
15401
|
refreshPageStatus,
|
|
15141
15402
|
refreshTabGrouping,
|
|
15142
15403
|
handleToolbarClick,
|
|
15404
|
+
handleDebuggingBarCancel,
|
|
15143
15405
|
cancelTargetHandoffs,
|
|
15144
15406
|
detachTargetState,
|
|
15145
15407
|
detachChildTargetState,
|
|
@@ -15394,6 +15656,13 @@ function createExtensionEventHandler(options) {
|
|
|
15394
15656
|
}
|
|
15395
15657
|
return;
|
|
15396
15658
|
}
|
|
15659
|
+
if (reason === "canceled_by_user") {
|
|
15660
|
+
if (eventTabId) {
|
|
15661
|
+
handleDebuggingBarCancel(eventTabId);
|
|
15662
|
+
detachTargetState(eventTabId, { releasedByUser: true });
|
|
15663
|
+
}
|
|
15664
|
+
return;
|
|
15665
|
+
}
|
|
15397
15666
|
if (eventTabId)
|
|
15398
15667
|
detachTargetState(eventTabId);
|
|
15399
15668
|
return;
|
|
@@ -16533,6 +16802,17 @@ function createTabPresentation(options) {
|
|
|
16533
16802
|
console.error("Toolbar toggle failed", error);
|
|
16534
16803
|
});
|
|
16535
16804
|
}
|
|
16805
|
+
function handleDebuggingBarCancel(tabId) {
|
|
16806
|
+
const sessions = getSessions();
|
|
16807
|
+
const target = registry.tabTargets.get(tabId);
|
|
16808
|
+
if (!target)
|
|
16809
|
+
return;
|
|
16810
|
+
const sessionId = pageStatusSessionId(target) ?? activeHandoffSessionIdForTab(tabId);
|
|
16811
|
+
if (sessionId && sessions.isExecuting(sessionId)) {
|
|
16812
|
+
relayLog("execute.stopped", { tabId, session: sessionId, from: "debugging-bar" });
|
|
16813
|
+
sessions.stopExecution(sessionId, debuggingBarDismissedStop, "debugging-bar-cancel");
|
|
16814
|
+
}
|
|
16815
|
+
}
|
|
16536
16816
|
function presentAttachedTarget(committedTarget) {
|
|
16537
16817
|
tabActivity.touch(committedTarget.tabId);
|
|
16538
16818
|
const tabId = committedTarget.tabId;
|
|
@@ -16567,6 +16847,7 @@ function createTabPresentation(options) {
|
|
|
16567
16847
|
requestHandoff,
|
|
16568
16848
|
onSessionExecuteStateChange,
|
|
16569
16849
|
handleToolbarClick,
|
|
16850
|
+
handleDebuggingBarCancel,
|
|
16570
16851
|
presentAttachedTarget
|
|
16571
16852
|
};
|
|
16572
16853
|
}
|
|
@@ -16715,8 +16996,9 @@ function createRelayTransportServers(deps) {
|
|
|
16715
16996
|
|
|
16716
16997
|
// src/cdp/root-target-lifecycle.ts
|
|
16717
16998
|
var DEFAULT_INVENTORY_COMMAND_TIMEOUT_MS = 5000;
|
|
16999
|
+
var DEFAULT_ATTACH_COMMAND_TIMEOUT_MS = 1e4;
|
|
16718
17000
|
|
|
16719
|
-
class
|
|
17001
|
+
class RootTargetTimeout extends TaggedError2()("RootTargetLifecycle.CommandTimeout", {
|
|
16720
17002
|
message: String3
|
|
16721
17003
|
}) {
|
|
16722
17004
|
}
|
|
@@ -16756,7 +17038,7 @@ class RootTargetLifecycle {
|
|
|
16756
17038
|
work.revision += 1;
|
|
16757
17039
|
this.failedTabs.delete(tabId);
|
|
16758
17040
|
}
|
|
16759
|
-
attach = fn("RootTargetLifecycle.attach")((options) => this.withPermit(options.tabId, options.expectedExtensionGeneration, (transition) => this.attachUnlocked(transition, options)));
|
|
17041
|
+
attach = fn("RootTargetLifecycle.attach")((options) => this.withPermit(options.tabId, options.expectedExtensionGeneration, (transition) => this.attachUnlocked(transition, options), this.options.attachCommandTimeoutMs ?? DEFAULT_ATTACH_COMMAND_TIMEOUT_MS));
|
|
16760
17042
|
reconcile = fn("RootTargetLifecycle.reconcile")((tabId, generation) => this.withPermit(tabId, generation, (transition) => this.reconcileUnlocked(transition)));
|
|
16761
17043
|
queue(options) {
|
|
16762
17044
|
if (this.closing)
|
|
@@ -16816,7 +17098,7 @@ class RootTargetLifecycle {
|
|
|
16816
17098
|
}).pipe(tapError((error) => sync2(() => lifecycle.options.reportError(options.errorMessage, error))), retry({
|
|
16817
17099
|
times: 2,
|
|
16818
17100
|
schedule: spaced(0).pipe(modifyDelay(({ attempt }) => succeed6(100 * attempt))),
|
|
16819
|
-
while: (error) => !(error instanceof GenerationChanged) && !(error instanceof
|
|
17101
|
+
while: (error) => !(error instanceof GenerationChanged) && !(error instanceof RootTargetTimeout) && !lifecycle.closing && generation === lifecycle.options.extension.generation(options.tabId) && revision === work.revision
|
|
16820
17102
|
}));
|
|
16821
17103
|
if (lifecycle.closing || generation !== lifecycle.options.extension.generation(options.tabId))
|
|
16822
17104
|
return null;
|
|
@@ -16913,7 +17195,7 @@ class RootTargetLifecycle {
|
|
|
16913
17195
|
const timeoutMs = transition.timeoutMs;
|
|
16914
17196
|
return this.step(transition, timeoutMs === undefined ? send : send.pipe(timeoutOrElse({
|
|
16915
17197
|
duration: timeoutMs,
|
|
16916
|
-
orElse: () => fail5(new
|
|
17198
|
+
orElse: () => fail5(new RootTargetTimeout({ message: `${method} did not answer within ${timeoutMs} ms on tab ${transition.tabId}` }))
|
|
16917
17199
|
})));
|
|
16918
17200
|
}
|
|
16919
17201
|
attachUnlocked = fnUntraced(function* (transition, options) {
|
|
@@ -16921,9 +17203,7 @@ class RootTargetLifecycle {
|
|
|
16921
17203
|
if (!options.alreadyAttached)
|
|
16922
17204
|
yield* this.step(transition, this.options.extension.send({ method: "debugger.attach", params: { tabId } }));
|
|
16923
17205
|
yield* this.command(transition, "Page.enable");
|
|
16924
|
-
yield*
|
|
16925
|
-
yield* this.command(transition, "Emulation.setFocusEmulationEnabled", { enabled: false });
|
|
16926
|
-
}).pipe(ignore);
|
|
17206
|
+
yield* this.command(transition, "Emulation.setFocusEmulationEnabled", { enabled: false }).pipe(catchIf((error) => !(error instanceof RootTargetTimeout), () => void_3));
|
|
16927
17207
|
yield* this.check(transition);
|
|
16928
17208
|
const result = yield* this.command(transition, "Target.getTargetInfo");
|
|
16929
17209
|
const reportedTargetInfo = getTargetInfo2(result.targetInfo);
|
|
@@ -17119,6 +17399,7 @@ class SessionNavigationGuard {
|
|
|
17119
17399
|
warnings = new Map;
|
|
17120
17400
|
rulesCache = new Map;
|
|
17121
17401
|
freshPopups = new Set;
|
|
17402
|
+
blanking = new Map;
|
|
17122
17403
|
constructor(dependencies) {
|
|
17123
17404
|
this.dependencies = dependencies;
|
|
17124
17405
|
}
|
|
@@ -17148,7 +17429,7 @@ class SessionNavigationGuard {
|
|
|
17148
17429
|
const rules = this.rules(options.sessionId);
|
|
17149
17430
|
if (!rules)
|
|
17150
17431
|
return;
|
|
17151
|
-
const url =
|
|
17432
|
+
const url = options.method === "Target.createTarget" ? createTargetUrl2(options.params) : getString2(options.params, "url");
|
|
17152
17433
|
if (url === undefined)
|
|
17153
17434
|
return;
|
|
17154
17435
|
const decision = await checkNavigationUrl(url, rules);
|
|
@@ -17163,8 +17444,16 @@ class SessionNavigationGuard {
|
|
|
17163
17444
|
this.freshPopups.add(target.tabId);
|
|
17164
17445
|
this.observeCommittedUrl(target, target.targetInfo.url);
|
|
17165
17446
|
}
|
|
17447
|
+
createdTabNavigated(target) {
|
|
17448
|
+
if (!this.enforced(target))
|
|
17449
|
+
return true;
|
|
17450
|
+
if ((this.blanking.get(target.tabId) ?? 0) > 0)
|
|
17451
|
+
return false;
|
|
17452
|
+
return this.observeCommittedUrl(target, target.targetInfo.url);
|
|
17453
|
+
}
|
|
17166
17454
|
forgetTab(tabId) {
|
|
17167
17455
|
this.freshPopups.delete(tabId);
|
|
17456
|
+
this.blanking.delete(tabId);
|
|
17168
17457
|
}
|
|
17169
17458
|
observeEvent(target, method, params) {
|
|
17170
17459
|
if (method !== "Page.frameNavigated" && method !== "Page.frameRequestedNavigation" && method !== "Page.frameStartedNavigating" && method !== "Network.responseReceived")
|
|
@@ -17215,14 +17504,15 @@ class SessionNavigationGuard {
|
|
|
17215
17504
|
observeCommittedUrl(target, url) {
|
|
17216
17505
|
const rules = this.rules(target.opencodeBrowserSessionId);
|
|
17217
17506
|
if (!rules)
|
|
17218
|
-
return;
|
|
17507
|
+
return true;
|
|
17219
17508
|
const decision = checkUrl(url, rules);
|
|
17220
17509
|
if (decision.allowed) {
|
|
17221
17510
|
if (!/^about:/.test(url))
|
|
17222
17511
|
this.freshPopups.delete(target.tabId);
|
|
17223
|
-
return;
|
|
17512
|
+
return true;
|
|
17224
17513
|
}
|
|
17225
17514
|
this.violation(target, url, decision.reason, "commit");
|
|
17515
|
+
return false;
|
|
17226
17516
|
}
|
|
17227
17517
|
violation(target, url, reason, _stage) {
|
|
17228
17518
|
const sessionId = target.opencodeBrowserSessionId;
|
|
@@ -17238,7 +17528,14 @@ class SessionNavigationGuard {
|
|
|
17238
17528
|
});
|
|
17239
17529
|
return;
|
|
17240
17530
|
}
|
|
17241
|
-
this.
|
|
17531
|
+
this.blanking.set(target.tabId, (this.blanking.get(target.tabId) ?? 0) + 1);
|
|
17532
|
+
this.dependencies.send(target.tabId, "Page.stopLoading", {}).catch(() => {}).then(() => this.dependencies.send(target.tabId, "Page.navigate", { url: "about:blank" })).catch(() => {}).finally(() => {
|
|
17533
|
+
const remaining = (this.blanking.get(target.tabId) ?? 1) - 1;
|
|
17534
|
+
if (remaining > 0)
|
|
17535
|
+
this.blanking.set(target.tabId, remaining);
|
|
17536
|
+
else
|
|
17537
|
+
this.blanking.delete(target.tabId);
|
|
17538
|
+
});
|
|
17242
17539
|
}
|
|
17243
17540
|
addWarning(sessionId, warning) {
|
|
17244
17541
|
const pending = this.warnings.get(sessionId) ?? [];
|
|
@@ -17534,6 +17831,7 @@ var makeRelay = fnUntraced(function* (options = {}) {
|
|
|
17534
17831
|
const known = ownersAcrossReconnect.get(targetId);
|
|
17535
17832
|
return known?.sessionId !== undefined && sessions.sessions.has(known.sessionId) ? { sessionId: known.sessionId, owner: known.owner } : undefined;
|
|
17536
17833
|
};
|
|
17834
|
+
const attachTimeoutMs = yield* Int("OPENCODE_BROWSER_ATTACH_TIMEOUT_MS").pipe(withDefault(1e4));
|
|
17537
17835
|
const rootLifecycle = yield* RootTargetLifecycle.make({
|
|
17538
17836
|
registry,
|
|
17539
17837
|
sessions: {
|
|
@@ -17553,7 +17851,8 @@ var makeRelay = fnUntraced(function* (options = {}) {
|
|
|
17553
17851
|
announceRoot: announceAttachedTarget,
|
|
17554
17852
|
announceChild: announceAttachedChildTarget
|
|
17555
17853
|
},
|
|
17556
|
-
reportError: (message, error) => console.error(message, error)
|
|
17854
|
+
reportError: (message, error) => console.error(message, error),
|
|
17855
|
+
attachCommandTimeoutMs: attachTimeoutMs
|
|
17557
17856
|
});
|
|
17558
17857
|
const settingsSync = createRelaySettingsSync({
|
|
17559
17858
|
browsers,
|
|
@@ -17626,17 +17925,42 @@ var makeRelay = fnUntraced(function* (options = {}) {
|
|
|
17626
17925
|
});
|
|
17627
17926
|
const createAndAttachTab = fnUntraced(function* (createOptions) {
|
|
17628
17927
|
const link = yield* sessionBrowser(createOptions.opencodeBrowserSessionId);
|
|
17629
|
-
const result = yield* sendToExtension({ method: "tabs.create", params: { url:
|
|
17928
|
+
const result = yield* sendToExtension({ method: "tabs.create", params: { url: "about:blank", active: createOptions.active, ...agentWindow ? { window: agentWindow } : {} } }, link);
|
|
17630
17929
|
const tabId = getNumber2(result, "tabId");
|
|
17631
17930
|
if (!tabId)
|
|
17632
17931
|
return yield* fail5(new Error("tabs.create did not return a tabId"));
|
|
17633
17932
|
announceTab(tabId);
|
|
17634
|
-
|
|
17933
|
+
const target = yield* rootLifecycle.attach({
|
|
17635
17934
|
tabId,
|
|
17636
17935
|
owner: "relay",
|
|
17637
17936
|
...createOptions.opencodeBrowserSessionId ? { opencodeBrowserSessionId: createOptions.opencodeBrowserSessionId } : {},
|
|
17638
17937
|
...createOptions.autoAttachParams ? { autoAttachParams: createOptions.autoAttachParams } : {}
|
|
17639
|
-
})
|
|
17938
|
+
}).pipe(tapError((error) => sync2(() => {
|
|
17939
|
+
relayLog("create.attach-failed", { tabId, error: error instanceof Error ? error.message : String(error) });
|
|
17940
|
+
sendExtensionBestEffort({ method: "tabs.remove", params: { tabId } });
|
|
17941
|
+
detachTargetState(tabId);
|
|
17942
|
+
})));
|
|
17943
|
+
const requested = createTargetUrl2({ url: createOptions.url });
|
|
17944
|
+
if (requested !== "about:blank") {
|
|
17945
|
+
const data = /^data:/i.test(requested.trim());
|
|
17946
|
+
const navigation = yield* (data ? navigateTopFrameToDataUrl({ tabId, params: { url: requested }, mainFrameIdsByTab, blankNavigationWaiters, registry, sendDebuggerCommand }) : sendDebuggerCommand({ tabId, method: "Page.navigate", params: { url: requested } })).pipe(catch_((error) => sync2(() => {
|
|
17947
|
+
relayLog("create.navigate-failed", { tabId, error: error instanceof Error ? error.message : String(error) });
|
|
17948
|
+
return;
|
|
17949
|
+
})));
|
|
17950
|
+
const errorText = getString2(navigation, "errorText");
|
|
17951
|
+
if (errorText)
|
|
17952
|
+
relayLog("create.navigate-failed", { tabId, errorText });
|
|
17953
|
+
else if (data && navigation === undefined)
|
|
17954
|
+
relayLog("create.data-skipped", { tabId });
|
|
17955
|
+
const current = yield* sendDebuggerCommand({ tabId, method: "Target.getTargetInfo", params: {} }).pipe(orElseSucceed(() => ({})));
|
|
17956
|
+
const targetInfo = getTargetInfo2(current.targetInfo);
|
|
17957
|
+
if (targetInfo && !isRestrictedTarget2(targetInfo) && navigationGuard.createdTabNavigated({ ...target, targetInfo })) {
|
|
17958
|
+
const updated = registry.updateConnectedTargetInfo({ tabId, targetInfo });
|
|
17959
|
+
if (updated?.kind === "root")
|
|
17960
|
+
return updated.target;
|
|
17961
|
+
}
|
|
17962
|
+
}
|
|
17963
|
+
return target;
|
|
17640
17964
|
});
|
|
17641
17965
|
const closeTargetByTargetId = fnUntraced(function* (targetId) {
|
|
17642
17966
|
const target = registry.targetsByTargetId.get(targetId);
|
|
@@ -17663,7 +17987,8 @@ var makeRelay = fnUntraced(function* (options = {}) {
|
|
|
17663
17987
|
rootLifecycle.invalidate(tabId);
|
|
17664
17988
|
if (detachOptions.updateExtension !== false) {
|
|
17665
17989
|
sendExtensionBestEffort({ method: "pageStatus.clear", params: { tabId } });
|
|
17666
|
-
|
|
17990
|
+
if (detachOptions.releasedByUser !== true || registry.tabTargets.get(tabId)?.owner !== "relay")
|
|
17991
|
+
presentation.scheduleTabGrouping(tabId, "tabs.ungroup");
|
|
17667
17992
|
sendExtensionBestEffort({ method: "action.setAttached", params: { tabId, attached: false } });
|
|
17668
17993
|
recordingRelay.abortRecordingForTab({ tabId, reason: "Tab detached" }).catch((error) => {
|
|
17669
17994
|
console.error("Failed to abort recording for detached tab", error);
|
|
@@ -17676,7 +18001,7 @@ var makeRelay = fnUntraced(function* (options = {}) {
|
|
|
17676
18001
|
if (detached) {
|
|
17677
18002
|
presentation.cancelTargetHandoffs(detached.target, "target-detached");
|
|
17678
18003
|
if (!detachOptions.preserveSessionTarget)
|
|
17679
|
-
sessions.markTargetDetached(detached.target.targetInfo.targetId);
|
|
18004
|
+
sessions.markTargetDetached(detached.target.targetInfo.targetId, { releasedByUser: detachOptions.releasedByUser === true });
|
|
17680
18005
|
contextDebugLog?.(`target-detached kind=root ${targetDiagnosticIdentity(registry, detached.target)}`);
|
|
17681
18006
|
}
|
|
17682
18007
|
cdpClients.detachTab(tabId, { destroyed: true });
|
|
@@ -17753,6 +18078,7 @@ var makeRelay = fnUntraced(function* (options = {}) {
|
|
|
17753
18078
|
refreshPageStatus: presentation.refreshPageStatus,
|
|
17754
18079
|
refreshTabGrouping: presentation.refreshTabGrouping,
|
|
17755
18080
|
handleToolbarClick: presentation.handleToolbarClick,
|
|
18081
|
+
handleDebuggingBarCancel: presentation.handleDebuggingBarCancel,
|
|
17756
18082
|
cancelTargetHandoffs: presentation.cancelTargetHandoffs,
|
|
17757
18083
|
detachTargetState,
|
|
17758
18084
|
detachChildTargetState,
|