@opencode/browse 0.0.14-dev.89 → 0.0.15-dev.100
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-de4qgw63.mjs → cli-6n92w2tr.mjs} +15 -15
- package/dist/cli.mjs +25 -19
- package/dist/{helpers-xmc7hjne.mjs → helpers-b363a8nv.mjs} +3 -1
- package/dist/{main-zzp23g5a.mjs → main-0pf5apge.mjs} +1 -1
- package/dist/{main-1vxdvhxq.mjs → main-0vy46qt0.mjs} +23 -7
- package/dist/{main-zv2rzdyy.mjs → main-1v1av1rf.mjs} +11 -4
- package/dist/{main-8sq2eksh.mjs → main-9eddfbwc.mjs} +1 -1
- package/dist/{main-xyak2r6b.mjs → main-bwkbapy8.mjs} +2 -2
- package/dist/main-ckssvk4c.mjs +18 -0
- package/dist/{main-3njywps1.mjs → main-cktye7tt.mjs} +2 -2
- package/dist/{main-skr1xf3n.mjs → main-njxjy1jj.mjs} +30 -15
- package/dist/{main-t7gk51hn.mjs → main-qrb9v6gy.mjs} +2 -2
- package/dist/{main-m9mn33h2.mjs → main-vbwhrdcz.mjs} +2 -2
- package/dist/main-zt63krh7.mjs +4 -0
- package/dist/{mcp-15evjbx4.mjs → mcp-rm9sf99b.mjs} +6 -6
- package/dist/{migrate-d5bj9eym.mjs → migrate-jpsgxnkg.mjs} +10 -13
- package/dist/{relay-kf1hanst.mjs → relay-hwwmvejt.mjs} +443 -156
- package/dist/{runtime-update-q0fbjj52.mjs → runtime-update-98db5p2b.mjs} +4 -4
- package/dist/{setup-bk39djpf.mjs → setup-cdwsskaa.mjs} +30 -11
- package/dist/{skill-text-mrxy6zpc.mjs → skill-text-28va391t.mjs} +16 -3
- package/dist/{supervisor-e60f40k9.mjs → supervisor-ncmszn2n.mjs} +3 -3
- package/dist/{update-pk34hat5.mjs → update-gc7wnpxj.mjs} +3 -3
- package/dist/{version-cm8f0bhc.mjs → version-5heaad93.mjs} +1 -1
- package/package.json +1 -1
- package/skills/browse/SKILL.md +16 -3
- package/dist/main-6qsa4k93.mjs +0 -4
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
opencodeBrowserVersion2,
|
|
3
3
|
opencodeBrowserBuildId2
|
|
4
|
-
} from "./main-
|
|
4
|
+
} from "./main-zt63krh7.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-0vy46qt0.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-1v1av1rf.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-0pf5apge.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-qrb9v6gy.mjs";
|
|
145
151
|
import {
|
|
146
152
|
defaultJournalBaseDir,
|
|
147
153
|
makeJournalEntry,
|
|
148
154
|
appendJournalEntry,
|
|
149
155
|
startJournalRetention
|
|
150
|
-
} from "./main-
|
|
156
|
+
} from "./main-cktye7tt.mjs";
|
|
151
157
|
import {
|
|
152
158
|
createUpdateWatcher2
|
|
153
|
-
} from "./main-
|
|
159
|
+
} from "./main-vbwhrdcz.mjs";
|
|
154
160
|
import {
|
|
155
161
|
relayHostname,
|
|
156
162
|
isLocalPeer,
|
|
157
163
|
installedDevExtension,
|
|
158
164
|
syncDevExtension
|
|
159
|
-
} from "./main-
|
|
165
|
+
} from "./main-bwkbapy8.mjs";
|
|
166
|
+
import {
|
|
167
|
+
legacyRoots
|
|
168
|
+
} from "./main-ckssvk4c.mjs";
|
|
160
169
|
import {
|
|
161
170
|
currentTimeMillis,
|
|
162
171
|
value,
|
|
@@ -268,7 +277,7 @@ import {
|
|
|
268
277
|
relayToken,
|
|
269
278
|
secretsEqual,
|
|
270
279
|
ensurePrivateDirectory
|
|
271
|
-
} from "./main-
|
|
280
|
+
} from "./main-9eddfbwc.mjs";
|
|
272
281
|
import {
|
|
273
282
|
isString,
|
|
274
283
|
isNumber,
|
|
@@ -2288,7 +2297,7 @@ function challengeWarning(outcome) {
|
|
|
2288
2297
|
// src/execute-realm.ts
|
|
2289
2298
|
import buffer2 from "node:buffer";
|
|
2290
2299
|
import crypto5 from "node:crypto";
|
|
2291
|
-
import
|
|
2300
|
+
import util4 from "node:util";
|
|
2292
2301
|
import vm3 from "node:vm";
|
|
2293
2302
|
|
|
2294
2303
|
// src/execute-realm/file-roots.ts
|
|
@@ -2393,9 +2402,12 @@ function executeFileRoots() {
|
|
|
2393
2402
|
const roots = [os2.tmpdir(), ...process.platform === "win32" ? [] : ["/tmp"], ...extra];
|
|
2394
2403
|
return [...new Set(roots.map(realpathOrSelf))];
|
|
2395
2404
|
}
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2405
|
+
var pathFlavor = (platform) => platform === "win32" ? path2.win32 : path2.posix;
|
|
2406
|
+
var foldCase = (value, platform) => platform === "win32" || platform === "darwin" ? value.toLowerCase() : value;
|
|
2407
|
+
function isInside(child, parent, platform = process.platform) {
|
|
2408
|
+
const paths = pathFlavor(platform);
|
|
2409
|
+
const relative = paths.relative(foldCase(parent, platform), foldCase(child, platform));
|
|
2410
|
+
return relative === "" || !paths.isAbsolute(relative) && relative !== ".." && !relative.startsWith(`..${paths.sep}`);
|
|
2399
2411
|
}
|
|
2400
2412
|
function realTarget(target) {
|
|
2401
2413
|
let current = path2.resolve(target);
|
|
@@ -2416,6 +2428,39 @@ function realTarget(target) {
|
|
|
2416
2428
|
class ExecuteFileAccessError extends Error {
|
|
2417
2429
|
name = "ExecuteFileAccessError";
|
|
2418
2430
|
}
|
|
2431
|
+
function browseDirectories() {
|
|
2432
|
+
return [...new Set([
|
|
2433
|
+
configRoot2(),
|
|
2434
|
+
dataRoot(),
|
|
2435
|
+
stateRoot(),
|
|
2436
|
+
cacheRoot(),
|
|
2437
|
+
...Object.values(defaultRoots()),
|
|
2438
|
+
...legacyRoots()
|
|
2439
|
+
])];
|
|
2440
|
+
}
|
|
2441
|
+
function isInstallSibling(target, binary, platform = process.platform) {
|
|
2442
|
+
const paths = pathFlavor(platform);
|
|
2443
|
+
const folder = foldCase(paths.dirname(binary), platform);
|
|
2444
|
+
const relative = paths.relative(folder, foldCase(target, platform));
|
|
2445
|
+
if (relative === "" || paths.isAbsolute(relative))
|
|
2446
|
+
return false;
|
|
2447
|
+
const [first] = relative.split(paths.sep);
|
|
2448
|
+
const name = foldCase(paths.basename(binary), platform);
|
|
2449
|
+
if (!first?.startsWith(`${name}.`))
|
|
2450
|
+
return false;
|
|
2451
|
+
const staged = first.slice(name.length + 1);
|
|
2452
|
+
return staged === "new" || staged.startsWith("old-") || staged.startsWith("migrate-") || /^\d+\.new$/.test(staged);
|
|
2453
|
+
}
|
|
2454
|
+
function isBinaryOrStaging(target, binary, platform) {
|
|
2455
|
+
const resolved = realTarget(binary);
|
|
2456
|
+
const stagedAt = path2.join(realTarget(path2.dirname(binary)), path2.basename(binary));
|
|
2457
|
+
return isInside(target, resolved, platform) || isInside(target, stagedAt, platform) || isInstallSibling(target, resolved, platform) || isInstallSibling(target, stagedAt, platform);
|
|
2458
|
+
}
|
|
2459
|
+
function isBrowseOwned(target, platform = process.platform) {
|
|
2460
|
+
if (browseDirectories().some((root) => isInside(target, realTarget(root), platform)))
|
|
2461
|
+
return true;
|
|
2462
|
+
return [installedBinaryPath(), installerBinaryPath()].some((binary) => isBinaryOrStaging(target, binary, platform));
|
|
2463
|
+
}
|
|
2419
2464
|
function assertExecuteFilePath(target, operation) {
|
|
2420
2465
|
if (typeof target !== "string" || target.length === 0) {
|
|
2421
2466
|
throw new ExecuteFileAccessError(`${operation}: file paths must be non-empty strings`);
|
|
@@ -2426,9 +2471,8 @@ function assertExecuteFilePath(target, operation) {
|
|
|
2426
2471
|
throw new ExecuteFileAccessError(`${operation}: use an absolute path inside ${describeRoots()}, for example files.path("name.png")`);
|
|
2427
2472
|
}
|
|
2428
2473
|
const resolved = realTarget(target);
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
throw new ExecuteFileAccessError(`${operation}: ${target} is inside browse's data directory, which execute code cannot access`);
|
|
2474
|
+
if (isBrowseOwned(resolved)) {
|
|
2475
|
+
throw new ExecuteFileAccessError(`${operation}: ${target} is inside browse's own files, which execute code cannot access`);
|
|
2432
2476
|
}
|
|
2433
2477
|
if (!roots.some((root) => isInside(resolved, root))) {
|
|
2434
2478
|
throw new ExecuteFileAccessError(`${operation}: ${target} is outside the execute file roots ${describeRoots()}. Set ${allowNodeEnvironmentVariable}=1 for unrestricted file access.`);
|
|
@@ -2668,12 +2712,68 @@ import inspector from "node:inspector";
|
|
|
2668
2712
|
import module from "node:module";
|
|
2669
2713
|
import net from "node:net";
|
|
2670
2714
|
import os3 from "node:os";
|
|
2715
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2671
2716
|
import tls from "node:tls";
|
|
2672
|
-
import
|
|
2717
|
+
import util3 from "node:util";
|
|
2673
2718
|
import v8 from "node:v8";
|
|
2674
2719
|
import vm from "node:vm";
|
|
2675
2720
|
import workerThreads from "node:worker_threads";
|
|
2676
2721
|
import * as acorn from "acorn";
|
|
2722
|
+
|
|
2723
|
+
// src/execute-realm/rejection-text.ts
|
|
2724
|
+
import util2 from "node:util";
|
|
2725
|
+
var placeholder = "reason not shown";
|
|
2726
|
+
var nativeStackGetter = Object.getOwnPropertyDescriptor(new Error, "stack")?.get;
|
|
2727
|
+
function safeErrorMessage(value, maxLength = 300) {
|
|
2728
|
+
if (typeof value === "string")
|
|
2729
|
+
return value.length > 0 ? value.slice(0, maxLength) : placeholder;
|
|
2730
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || typeof value === "symbol") {
|
|
2731
|
+
return String(value).slice(0, maxLength);
|
|
2732
|
+
}
|
|
2733
|
+
if (!isSafeNativeError(value))
|
|
2734
|
+
return placeholder;
|
|
2735
|
+
const message = ownDataProperty(value, "message");
|
|
2736
|
+
return typeof message === "string" && message.length > 0 ? message.slice(0, maxLength) : placeholder;
|
|
2737
|
+
}
|
|
2738
|
+
function safeErrorStack(value) {
|
|
2739
|
+
if (!isSafeHostError(value))
|
|
2740
|
+
return;
|
|
2741
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, "stack");
|
|
2742
|
+
if (descriptor === undefined)
|
|
2743
|
+
return;
|
|
2744
|
+
if ("value" in descriptor)
|
|
2745
|
+
return typeof descriptor.value === "string" ? descriptor.value : undefined;
|
|
2746
|
+
if (descriptor.get === undefined || descriptor.get !== nativeStackGetter)
|
|
2747
|
+
return;
|
|
2748
|
+
try {
|
|
2749
|
+
const stack = descriptor.get.call(value);
|
|
2750
|
+
return typeof stack === "string" ? stack : undefined;
|
|
2751
|
+
} catch {
|
|
2752
|
+
return;
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2755
|
+
function isSafeNativeError(value) {
|
|
2756
|
+
return typeof value === "object" && value !== null && !util2.types.isProxy(value) && util2.types.isNativeError(value);
|
|
2757
|
+
}
|
|
2758
|
+
function isSafeHostError(value) {
|
|
2759
|
+
if (!isSafeNativeError(value))
|
|
2760
|
+
return false;
|
|
2761
|
+
let prototype = Object.getPrototypeOf(value);
|
|
2762
|
+
for (let depth = 0;prototype !== null && depth < 32; depth += 1) {
|
|
2763
|
+
if (prototype === Error.prototype)
|
|
2764
|
+
return true;
|
|
2765
|
+
if (util2.types.isProxy(prototype))
|
|
2766
|
+
return false;
|
|
2767
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
2768
|
+
}
|
|
2769
|
+
return false;
|
|
2770
|
+
}
|
|
2771
|
+
function ownDataProperty(value, key) {
|
|
2772
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
2773
|
+
return descriptor !== undefined && "value" in descriptor ? descriptor.value : undefined;
|
|
2774
|
+
}
|
|
2775
|
+
|
|
2776
|
+
// src/execute-realm/membrane-policy.ts
|
|
2677
2777
|
var deniedHostValues = new Map([
|
|
2678
2778
|
[process, "process"],
|
|
2679
2779
|
[globalThis, "the relay's global object"],
|
|
@@ -2697,9 +2797,9 @@ var deniedHostValues = new Map([
|
|
|
2697
2797
|
[workerThreads, "worker_threads"],
|
|
2698
2798
|
[globalThis.fetch, "Node fetch"],
|
|
2699
2799
|
[eval, "eval"],
|
|
2700
|
-
[
|
|
2701
|
-
[
|
|
2702
|
-
[
|
|
2800
|
+
[util3.inspect, "host object inspection"],
|
|
2801
|
+
[util3.format, "host object formatting"],
|
|
2802
|
+
[util3.formatWithOptions, "host object formatting"],
|
|
2703
2803
|
[crypto4.setEngine, "loading native crypto engines"],
|
|
2704
2804
|
[events2.setMaxListeners, "changing shared event-emitter defaults or prototypes"],
|
|
2705
2805
|
...[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 +2905,111 @@ function isObjectLike(value) {
|
|
|
2805
2905
|
return typeof value === "object" && value !== null || typeof value === "function";
|
|
2806
2906
|
}
|
|
2807
2907
|
var isHiddenKey = (key) => typeof key === "string" && key.startsWith("_");
|
|
2808
|
-
var
|
|
2809
|
-
var
|
|
2908
|
+
var activeOwner;
|
|
2909
|
+
var rejectionContext = new AsyncLocalStorage;
|
|
2910
|
+
var promiseOwners = new WeakMap;
|
|
2810
2911
|
var stopPromiseHook;
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2912
|
+
var promiseHookUsers = 0;
|
|
2913
|
+
function enterRejectionOwner(owner) {
|
|
2914
|
+
const previous = activeOwner;
|
|
2915
|
+
activeOwner = owner;
|
|
2916
|
+
return () => {
|
|
2917
|
+
activeOwner = previous;
|
|
2918
|
+
};
|
|
2919
|
+
}
|
|
2920
|
+
function runWithRejectionOwner(owner, run) {
|
|
2921
|
+
return rejectionContext.run(owner, () => {
|
|
2922
|
+
const restore = enterRejectionOwner(owner);
|
|
2923
|
+
try {
|
|
2924
|
+
return run();
|
|
2925
|
+
} finally {
|
|
2926
|
+
restore();
|
|
2927
|
+
}
|
|
2928
|
+
});
|
|
2929
|
+
}
|
|
2930
|
+
function retainPromiseHook() {
|
|
2931
|
+
promiseHookUsers += 1;
|
|
2932
|
+
if (promiseHookUsers === 1) {
|
|
2933
|
+
stopPromiseHook = v8.promiseHooks.createHook({ init(promise, parent) {
|
|
2934
|
+
const owner = activeOwner ?? rejectionContext.getStore() ?? (parent ? promiseOwners.get(parent) : undefined);
|
|
2935
|
+
if (owner)
|
|
2936
|
+
promiseOwners.set(promise, owner);
|
|
2826
2937
|
} });
|
|
2827
2938
|
}
|
|
2939
|
+
let released = false;
|
|
2828
2940
|
return () => {
|
|
2829
|
-
|
|
2830
|
-
|
|
2941
|
+
if (released)
|
|
2942
|
+
return;
|
|
2943
|
+
released = true;
|
|
2944
|
+
promiseHookUsers -= 1;
|
|
2945
|
+
if (promiseHookUsers === 0 && stopPromiseHook) {
|
|
2831
2946
|
stopPromiseHook();
|
|
2832
2947
|
stopPromiseHook = undefined;
|
|
2833
2948
|
}
|
|
2834
2949
|
};
|
|
2835
2950
|
}
|
|
2951
|
+
function trackPromisesOf(owner) {
|
|
2952
|
+
const restoreOwner = enterRejectionOwner(owner);
|
|
2953
|
+
if (process.versions.bun) {
|
|
2954
|
+
const entered = { owner, at: Date.now() };
|
|
2955
|
+
lastOwner = entered;
|
|
2956
|
+
return () => {
|
|
2957
|
+
restoreOwner();
|
|
2958
|
+
entered.at = Date.now();
|
|
2959
|
+
};
|
|
2960
|
+
}
|
|
2961
|
+
const releaseHook = retainPromiseHook();
|
|
2962
|
+
return () => {
|
|
2963
|
+
restoreOwner();
|
|
2964
|
+
releaseHook();
|
|
2965
|
+
};
|
|
2966
|
+
}
|
|
2836
2967
|
var realmsByPromisePrototype = new WeakMap;
|
|
2837
|
-
var
|
|
2838
|
-
var
|
|
2968
|
+
var lastOwner;
|
|
2969
|
+
var lastOwnerWindowMs = 1000;
|
|
2839
2970
|
function registerRealmPromisePrototype(prototype, realm) {
|
|
2840
2971
|
if (process.versions.bun)
|
|
2841
2972
|
realmsByPromisePrototype.set(prototype, realm);
|
|
2842
2973
|
}
|
|
2843
|
-
function
|
|
2844
|
-
|
|
2845
|
-
if (byPrototype)
|
|
2846
|
-
return byPrototype;
|
|
2847
|
-
if (!lastRealm || lastRealm.realm.isStopped)
|
|
2974
|
+
function bunRejectionOwner(promise) {
|
|
2975
|
+
if (!lastOwner || lastOwner.owner.isStopped)
|
|
2848
2976
|
return;
|
|
2849
|
-
return
|
|
2977
|
+
return activeOwner === lastOwner.owner || Date.now() - lastOwner.at <= lastOwnerWindowMs ? lastOwner.owner : undefined;
|
|
2850
2978
|
}
|
|
2851
|
-
function handleExecuteRealmRejection(promise) {
|
|
2852
|
-
const
|
|
2853
|
-
|
|
2979
|
+
function handleExecuteRealmRejection(promise, reason) {
|
|
2980
|
+
const byPrototype = process.versions.bun ? realmsByPromisePrototype.get(Object.getPrototypeOf(promise)) : undefined;
|
|
2981
|
+
const exact = promiseOwners.get(promise) ?? byPrototype;
|
|
2982
|
+
const owner = exact ?? (process.versions.bun ? bunRejectionOwner(promise) : undefined);
|
|
2983
|
+
if (!owner)
|
|
2854
2984
|
return false;
|
|
2855
|
-
|
|
2985
|
+
owner.handleUnhandledRejection(reason, exact !== undefined);
|
|
2856
2986
|
return true;
|
|
2857
2987
|
}
|
|
2988
|
+
function unhandledExecuteRejectionWarning(detail, certain) {
|
|
2989
|
+
if (!certain) {
|
|
2990
|
+
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.";
|
|
2991
|
+
}
|
|
2992
|
+
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.`;
|
|
2993
|
+
}
|
|
2994
|
+
function handleRealmUnhandledRejection(realm, cause, certain, warn, pending) {
|
|
2995
|
+
if (realm.isStopped)
|
|
2996
|
+
return;
|
|
2997
|
+
const description = certain ? rejectionDescription(realm, cause) : "a rejected promise";
|
|
2998
|
+
if (!pending) {
|
|
2999
|
+
try {
|
|
3000
|
+
warn?.(unhandledExecuteRejectionWarning(description, certain));
|
|
3001
|
+
} catch {}
|
|
3002
|
+
}
|
|
3003
|
+
realm.dispose(new Error(`Unhandled execute rejection: ${description}; JavaScript state will reset before the next execute`));
|
|
3004
|
+
}
|
|
3005
|
+
function rejectionDescription(realm, cause) {
|
|
3006
|
+
if (isObjectLike(cause)) {
|
|
3007
|
+
const host = realm.hostValueForSandboxValue(cause);
|
|
3008
|
+
if (host !== undefined)
|
|
3009
|
+
return safeErrorMessage(host);
|
|
3010
|
+
}
|
|
3011
|
+
return safeErrorMessage(cause);
|
|
3012
|
+
}
|
|
2858
3013
|
var thrownByRealm = new WeakMap;
|
|
2859
3014
|
function tagThrownByRealm(value, realm) {
|
|
2860
3015
|
if (!thrownByRealm.has(value))
|
|
@@ -2987,11 +3142,13 @@ class ExecuteRealm {
|
|
|
2987
3142
|
entryScript;
|
|
2988
3143
|
global;
|
|
2989
3144
|
onHostCall;
|
|
3145
|
+
onUnhandledRejection;
|
|
2990
3146
|
refuseDynamicImport = () => {
|
|
2991
3147
|
throw new this.SandboxError("import() is not available in execute code");
|
|
2992
3148
|
};
|
|
2993
3149
|
constructor(options = {}) {
|
|
2994
3150
|
this.onHostCall = options.onHostCall;
|
|
3151
|
+
this.onUnhandledRejection = options.onUnhandledRejection;
|
|
2995
3152
|
const importModuleDynamically = this.refuseDynamicImport;
|
|
2996
3153
|
const dontContextify = vm3.constants?.DONT_CONTEXTIFY;
|
|
2997
3154
|
this.context = vm3.createContext(dontContextify ?? Object.create(null), {
|
|
@@ -3036,6 +3193,12 @@ class ExecuteRealm {
|
|
|
3036
3193
|
get isStopped() {
|
|
3037
3194
|
return this.stopped !== undefined;
|
|
3038
3195
|
}
|
|
3196
|
+
handleUnhandledRejection(cause, certain) {
|
|
3197
|
+
handleRealmUnhandledRejection(this, cause, certain, this.onUnhandledRejection, this.pendingRuns.size > 0);
|
|
3198
|
+
}
|
|
3199
|
+
hostValueForSandboxValue(value) {
|
|
3200
|
+
return isObjectLike(value) ? this.hostBySandboxProxy.get(value) : undefined;
|
|
3201
|
+
}
|
|
3039
3202
|
enter(entry) {
|
|
3040
3203
|
if (this.stopped)
|
|
3041
3204
|
throw this.stopped;
|
|
@@ -3154,7 +3317,7 @@ class ExecuteRealm {
|
|
|
3154
3317
|
throw this.sandboxError(`${denied} is not available in execute code. Set ${allowNodeEnvironmentVariable}=1 for full Node access.`);
|
|
3155
3318
|
if (this.isSandboxNative(value))
|
|
3156
3319
|
return value;
|
|
3157
|
-
if (
|
|
3320
|
+
if (util4.types.isPromise(value))
|
|
3158
3321
|
return this.toSandboxPromise(value);
|
|
3159
3322
|
if (Buffer.isBuffer(value)) {
|
|
3160
3323
|
const copy = Buffer.alloc(value.length);
|
|
@@ -3163,11 +3326,11 @@ class ExecuteRealm {
|
|
|
3163
3326
|
this.sandboxProxyByHost.set(value, proxy);
|
|
3164
3327
|
return proxy;
|
|
3165
3328
|
}
|
|
3166
|
-
if (
|
|
3329
|
+
if (util4.types.isArrayBuffer(value)) {
|
|
3167
3330
|
const SandboxUint8Array = this.sandboxIntrinsics.Uint8Array;
|
|
3168
3331
|
return new SandboxUint8Array(new Uint8Array(value)).buffer;
|
|
3169
3332
|
}
|
|
3170
|
-
if (
|
|
3333
|
+
if (util4.types.isTypedArray(value) && !Buffer.isBuffer(value)) {
|
|
3171
3334
|
const name = Object.prototype.toString.call(value).slice(8, -1);
|
|
3172
3335
|
const Constructor = this.sandboxIntrinsics[name] ?? this.sandboxIntrinsics.Uint8Array;
|
|
3173
3336
|
return new Constructor(value);
|
|
@@ -3177,7 +3340,7 @@ class ExecuteRealm {
|
|
|
3177
3340
|
throw this.sandboxError(deniedClass);
|
|
3178
3341
|
if (!this.forceProxy.has(value) && typeof value === "object") {
|
|
3179
3342
|
const prototype = Reflect.getPrototypeOf(value);
|
|
3180
|
-
if (Array.isArray(value) && prototype === Array.prototype ||
|
|
3343
|
+
if (Array.isArray(value) && prototype === Array.prototype || util4.types.isArgumentsObject(value)) {
|
|
3181
3344
|
const output = [];
|
|
3182
3345
|
Reflect.setPrototypeOf(output, this.sandboxArrayPrototype);
|
|
3183
3346
|
seen.set(value, output);
|
|
@@ -3186,7 +3349,7 @@ class ExecuteRealm {
|
|
|
3186
3349
|
output[index] = this.toSandbox(array[index], seen);
|
|
3187
3350
|
return output;
|
|
3188
3351
|
}
|
|
3189
|
-
if ((prototype === Object.prototype || prototype === null) && !Object.hasOwn(value, "constructor") && !
|
|
3352
|
+
if ((prototype === Object.prototype || prototype === null) && !Object.hasOwn(value, "constructor") && !util4.types.isProxy(value)) {
|
|
3190
3353
|
const output = Object.create(prototype === null ? null : this.sandboxObjectPrototype);
|
|
3191
3354
|
seen.set(value, output);
|
|
3192
3355
|
for (const key of Object.keys(value)) {
|
|
@@ -3438,16 +3601,16 @@ class ExecuteRealm {
|
|
|
3438
3601
|
}
|
|
3439
3602
|
}
|
|
3440
3603
|
copyToHost(value, seen) {
|
|
3441
|
-
if (
|
|
3604
|
+
if (util4.types.isPromise(value))
|
|
3442
3605
|
return this.toHostPromise(value);
|
|
3443
|
-
if (
|
|
3606
|
+
if (util4.types.isDate(value))
|
|
3444
3607
|
return new Date(Date.prototype.getTime.call(value));
|
|
3445
|
-
if (
|
|
3608
|
+
if (util4.types.isRegExp(value)) {
|
|
3446
3609
|
const source = Reflect.get(value, "source");
|
|
3447
3610
|
const flags = Reflect.get(value, "flags");
|
|
3448
3611
|
return new RegExp(String(source), String(flags));
|
|
3449
3612
|
}
|
|
3450
|
-
if (
|
|
3613
|
+
if (util4.types.isNativeError(value) || value instanceof this.SandboxError) {
|
|
3451
3614
|
const name = String(Reflect.get(value, "name") ?? "Error");
|
|
3452
3615
|
const output = new Error(String(Reflect.get(value, "message") ?? ""));
|
|
3453
3616
|
seen.set(value, output);
|
|
@@ -3465,26 +3628,26 @@ class ExecuteRealm {
|
|
|
3465
3628
|
Object.defineProperty(output, "cause", { value: this.toHost(cause, seen), configurable: true, writable: true });
|
|
3466
3629
|
return output;
|
|
3467
3630
|
}
|
|
3468
|
-
if (
|
|
3631
|
+
if (util4.types.isMap(value)) {
|
|
3469
3632
|
const output = new Map;
|
|
3470
3633
|
seen.set(value, output);
|
|
3471
3634
|
Map.prototype.forEach.call(value, (item, key) => output.set(this.toHost(key, seen), this.toHost(item, seen)));
|
|
3472
3635
|
return output;
|
|
3473
3636
|
}
|
|
3474
|
-
if (
|
|
3637
|
+
if (util4.types.isSet(value)) {
|
|
3475
3638
|
const output = new Set;
|
|
3476
3639
|
seen.set(value, output);
|
|
3477
3640
|
Set.prototype.forEach.call(value, (item) => output.add(this.toHost(item, seen)));
|
|
3478
3641
|
return output;
|
|
3479
3642
|
}
|
|
3480
|
-
if (
|
|
3643
|
+
if (util4.types.isArrayBuffer(value))
|
|
3481
3644
|
return new Uint8Array(new Uint8Array(value)).buffer;
|
|
3482
|
-
if (
|
|
3645
|
+
if (util4.types.isTypedArray(value)) {
|
|
3483
3646
|
const name = Object.prototype.toString.call(value).slice(8, -1);
|
|
3484
3647
|
const Constructor = globalThis[name] ?? Uint8Array;
|
|
3485
3648
|
return new Constructor(value);
|
|
3486
3649
|
}
|
|
3487
|
-
if (Array.isArray(value) ||
|
|
3650
|
+
if (Array.isArray(value) || util4.types.isArgumentsObject(value)) {
|
|
3488
3651
|
const output = [];
|
|
3489
3652
|
seen.set(value, output);
|
|
3490
3653
|
const array = value;
|
|
@@ -3615,6 +3778,45 @@ import https2 from "node:https";
|
|
|
3615
3778
|
import os4 from "node:os";
|
|
3616
3779
|
import * as acorn2 from "acorn";
|
|
3617
3780
|
|
|
3781
|
+
// src/execute/rejection-scope.ts
|
|
3782
|
+
var defaultRejectionOwnershipExpiryMs = 10 * 60000;
|
|
3783
|
+
|
|
3784
|
+
class ExecuteRejectionScope {
|
|
3785
|
+
releaseHook;
|
|
3786
|
+
expiry;
|
|
3787
|
+
expiryMs;
|
|
3788
|
+
onRejection;
|
|
3789
|
+
constructor(options = {}) {
|
|
3790
|
+
this.onRejection = options.onRejection;
|
|
3791
|
+
this.expiryMs = options.expiryMs ?? defaultRejectionOwnershipExpiryMs;
|
|
3792
|
+
}
|
|
3793
|
+
begin() {
|
|
3794
|
+
if (process.versions.bun || this.releaseHook)
|
|
3795
|
+
return;
|
|
3796
|
+
this.releaseHook = retainPromiseHook();
|
|
3797
|
+
this.expiry = setTimeout(() => this.end(), this.expiryMs);
|
|
3798
|
+
this.expiry.unref?.();
|
|
3799
|
+
}
|
|
3800
|
+
invoke(run) {
|
|
3801
|
+
if (process.versions.bun)
|
|
3802
|
+
return run();
|
|
3803
|
+
return runWithRejectionOwner(this, run);
|
|
3804
|
+
}
|
|
3805
|
+
end() {
|
|
3806
|
+
if (this.expiry !== undefined) {
|
|
3807
|
+
clearTimeout(this.expiry);
|
|
3808
|
+
this.expiry = undefined;
|
|
3809
|
+
}
|
|
3810
|
+
this.releaseHook?.();
|
|
3811
|
+
this.releaseHook = undefined;
|
|
3812
|
+
}
|
|
3813
|
+
handleUnhandledRejection(cause, certain) {
|
|
3814
|
+
try {
|
|
3815
|
+
this.onRejection?.(unhandledExecuteRejectionWarning(safeErrorMessage(cause), certain));
|
|
3816
|
+
} catch {}
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3819
|
+
|
|
3618
3820
|
// src/execute/console.ts
|
|
3619
3821
|
var sessions = new WeakMap;
|
|
3620
3822
|
var listeners = new WeakMap;
|
|
@@ -3675,7 +3877,7 @@ function describe(arg) {
|
|
|
3675
3877
|
}
|
|
3676
3878
|
|
|
3677
3879
|
// src/execute/log-capture.ts
|
|
3678
|
-
import
|
|
3880
|
+
import util5 from "node:util";
|
|
3679
3881
|
var maxCapturedPageLogs = 50;
|
|
3680
3882
|
var maxCapturedScriptLogs = 100;
|
|
3681
3883
|
function createExecuteLogCapture(limits = {}) {
|
|
@@ -3864,7 +4066,7 @@ function formatLogValue(value) {
|
|
|
3864
4066
|
if (isString(value)) {
|
|
3865
4067
|
return value;
|
|
3866
4068
|
}
|
|
3867
|
-
return
|
|
4069
|
+
return util5.inspect(value, { depth: 4, colors: false, maxArrayLength: 100, maxStringLength: 1000 });
|
|
3868
4070
|
}
|
|
3869
4071
|
|
|
3870
4072
|
// src/execute/target-selection.ts
|
|
@@ -4369,7 +4571,7 @@ var sandboxGlobalKeys = [
|
|
|
4369
4571
|
"pageConsole",
|
|
4370
4572
|
"secrets"
|
|
4371
4573
|
];
|
|
4372
|
-
async function runUserCode({ code, globals, realm }) {
|
|
4574
|
+
async function runUserCode({ code, globals, realm, onUnhandledRejection }) {
|
|
4373
4575
|
const logCapture = createExecuteLogCapture();
|
|
4374
4576
|
const navigations = [];
|
|
4375
4577
|
const onConsole = (message) => {
|
|
@@ -4432,8 +4634,14 @@ ${wrapCodeWithModuleAliases(code, Object.keys(sandboxModules))}
|
|
|
4432
4634
|
const AsyncFunction = async function() {}.constructor;
|
|
4433
4635
|
const fn = new AsyncFunction("console", ...sandboxGlobalKeys, `${wrapCodeWithModuleAliases(code, Object.keys(nodeModules))}
|
|
4434
4636
|
//# sourceURL=${executeFilename}`);
|
|
4435
|
-
const
|
|
4436
|
-
|
|
4637
|
+
const scope = process.versions.bun || !onUnhandledRejection ? undefined : new ExecuteRejectionScope({ onRejection: onUnhandledRejection });
|
|
4638
|
+
scope?.begin();
|
|
4639
|
+
try {
|
|
4640
|
+
const result = await (scope ? scope.invoke(() => fn(...values)) : fn(...values));
|
|
4641
|
+
return { result, ...buildResultMetadata() };
|
|
4642
|
+
} finally {
|
|
4643
|
+
scope?.end();
|
|
4644
|
+
}
|
|
4437
4645
|
} catch (cause) {
|
|
4438
4646
|
const error = cause instanceof Error ? cause : new Error("execute sandbox code", { cause });
|
|
4439
4647
|
const metadata = buildResultMetadata();
|
|
@@ -4847,7 +5055,7 @@ class DefaultPageHost {
|
|
|
4847
5055
|
}
|
|
4848
5056
|
|
|
4849
5057
|
// src/execute/result-formatting.ts
|
|
4850
|
-
import
|
|
5058
|
+
import util6 from "node:util";
|
|
4851
5059
|
var maxExecuteResultChars = 1e5;
|
|
4852
5060
|
function boundExecuteResult(text, value, hasValue) {
|
|
4853
5061
|
const valueChars = hasValue && value !== null && typeof value === "object" ? safeJsonStringify(value)?.length ?? 0 : typeof value === "string" ? value.length : 0;
|
|
@@ -4869,7 +5077,7 @@ function stringifyResult(result) {
|
|
|
4869
5077
|
if (result === undefined) {
|
|
4870
5078
|
return "undefined";
|
|
4871
5079
|
}
|
|
4872
|
-
return
|
|
5080
|
+
return util6.inspect(result, { depth: 3, colors: false, maxArrayLength: 50, maxStringLength: 4000 });
|
|
4873
5081
|
}
|
|
4874
5082
|
var maxJsonSafeDepth = 8;
|
|
4875
5083
|
var maxJsonSafeBytes = 32 * 1024;
|
|
@@ -9859,7 +10067,8 @@ class ExecuteSandbox extends DefaultPageHost {
|
|
|
9859
10067
|
return new ExecuteRealm({
|
|
9860
10068
|
onHostCall: (fn, receiver, args) => {
|
|
9861
10069
|
this.addWarningOnce(pageVisibleApiWarning(fn, receiver, args));
|
|
9862
|
-
}
|
|
10070
|
+
},
|
|
10071
|
+
onUnhandledRejection: (warning) => this.addWarningOnce(warning)
|
|
9863
10072
|
});
|
|
9864
10073
|
}
|
|
9865
10074
|
execute(code, options = {}) {
|
|
@@ -9874,7 +10083,12 @@ class ExecuteSandbox extends DefaultPageHost {
|
|
|
9874
10083
|
for (const warning of pageVisibleApiSourceWarnings(code))
|
|
9875
10084
|
this.addWarningOnce(warning);
|
|
9876
10085
|
const globals = await this.getGlobals(options);
|
|
9877
|
-
const { result, logs, logSummary, aftermath } = await runUserCode({
|
|
10086
|
+
const { result, logs, logSummary, aftermath } = await runUserCode({
|
|
10087
|
+
code,
|
|
10088
|
+
globals,
|
|
10089
|
+
...this.realm ? { realm: this.realm } : {},
|
|
10090
|
+
onUnhandledRejection: (warning) => this.addWarningOnce(warning)
|
|
10091
|
+
}).then(async (completed) => ({ ...completed, aftermath: await this.withChallenge(globals.page, completed.aftermath, false) })).catch(async (error) => {
|
|
9878
10092
|
if (!(error instanceof ExecuteCodeError) || !error.aftermath)
|
|
9879
10093
|
throw error;
|
|
9880
10094
|
throw new ExecuteCodeError(error.originalError, error.logs, error.logSummary, await this.withChallenge(globals.page, error.aftermath, true));
|
|
@@ -14621,28 +14835,56 @@ function replayTargetCreated(options) {
|
|
|
14621
14835
|
}
|
|
14622
14836
|
}
|
|
14623
14837
|
|
|
14624
|
-
// src/relay/
|
|
14625
|
-
|
|
14626
|
-
|
|
14627
|
-
|
|
14628
|
-
|
|
14629
|
-
|
|
14630
|
-
|
|
14631
|
-
|
|
14632
|
-
|
|
14633
|
-
|
|
14838
|
+
// src/relay/data-navigation.ts
|
|
14839
|
+
var navigateTopFrameToDataUrl = fnUntraced(function* (options) {
|
|
14840
|
+
const url = getString2(options.params, "url")?.trim();
|
|
14841
|
+
if (!url || !/^data:/i.test(url))
|
|
14842
|
+
return;
|
|
14843
|
+
const { tabId, mainFrameIdsByTab, blankNavigationWaiters, registry, sendDebuggerCommand } = options;
|
|
14844
|
+
const frameId = mainFrameIdsByTab.get(tabId) ?? registry.tabTargets.get(tabId)?.targetInfo.targetId;
|
|
14845
|
+
const requestedFrameId = getString2(options.params, "frameId");
|
|
14846
|
+
if (!frameId || requestedFrameId !== undefined && requestedFrameId !== frameId || blankNavigationWaiters.has(tabId))
|
|
14847
|
+
return;
|
|
14848
|
+
const html = yield* tryPromise(() => dataUrlDocument2(url)).pipe(orElseSucceed(() => {
|
|
14849
|
+
return;
|
|
14850
|
+
}));
|
|
14851
|
+
if (html === undefined)
|
|
14852
|
+
return;
|
|
14853
|
+
const committedLoaders = new Set;
|
|
14854
|
+
let loaderCommitted = () => {};
|
|
14855
|
+
blankNavigationWaiters.set(tabId, (frameUrl, loaderId) => {
|
|
14856
|
+
if (frameUrl !== "about:blank" || loaderId === undefined)
|
|
14634
14857
|
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);
|
|
14858
|
+
committedLoaders.add(loaderId);
|
|
14859
|
+
loaderCommitted(loaderId);
|
|
14644
14860
|
});
|
|
14861
|
+
return yield* gen(function* () {
|
|
14862
|
+
const navigated = yield* sendDebuggerCommand({ tabId, method: "Page.navigate", params: { url: "about:blank", frameId } });
|
|
14863
|
+
const loaderId = getString2(navigated, "loaderId");
|
|
14864
|
+
if (getString2(navigated, "errorText") || loaderId === undefined)
|
|
14865
|
+
return navigated;
|
|
14866
|
+
if (!committedLoaders.has(loaderId)) {
|
|
14867
|
+
const committed = yield* promise(() => new Promise((resolve) => {
|
|
14868
|
+
loaderCommitted = (id) => {
|
|
14869
|
+
if (id === loaderId)
|
|
14870
|
+
resolve();
|
|
14871
|
+
};
|
|
14872
|
+
})).pipe(timeoutOption(1e4));
|
|
14873
|
+
if (committed._tag === "None")
|
|
14874
|
+
return navigated;
|
|
14875
|
+
}
|
|
14876
|
+
yield* sendDebuggerCommand({ tabId, method: "Page.setDocumentContent", params: { frameId, html } });
|
|
14877
|
+
relayLog("navigate.data", { tabId, chars: html.length });
|
|
14878
|
+
return { frameId: getString2(navigated, "frameId") ?? frameId, loaderId };
|
|
14879
|
+
}).pipe(ensuring(sync2(() => {
|
|
14880
|
+
blankNavigationWaiters.delete(tabId);
|
|
14881
|
+
})));
|
|
14645
14882
|
});
|
|
14883
|
+
|
|
14884
|
+
// src/relay/process-guard.ts
|
|
14885
|
+
import http4 from "node:http";
|
|
14886
|
+
|
|
14887
|
+
// src/relay/process-faults.ts
|
|
14646
14888
|
var suppressedProcessFaults = { count: 0 };
|
|
14647
14889
|
function relayProcessFaultSummary() {
|
|
14648
14890
|
return {
|
|
@@ -14654,21 +14896,25 @@ function relayProcessFaultSummary() {
|
|
|
14654
14896
|
function shouldSuppressRelayProcessFault(cause) {
|
|
14655
14897
|
if (isPatchrightProtocolError(cause))
|
|
14656
14898
|
return true;
|
|
14657
|
-
const errorText =
|
|
14658
|
-
${cause
|
|
14899
|
+
const errorText = `${safeErrorMessage(cause)}
|
|
14900
|
+
${safeErrorStack(cause) ?? ""}`;
|
|
14659
14901
|
return /playwright-core|patchright-core|coreBundle|Duplicate target/i.test(errorText);
|
|
14660
14902
|
}
|
|
14661
14903
|
function isPatchrightProtocolError(cause) {
|
|
14662
|
-
|
|
14904
|
+
if (!isSafeHostError(cause))
|
|
14905
|
+
return false;
|
|
14906
|
+
const type = Object.getOwnPropertyDescriptor(cause, "type")?.value;
|
|
14907
|
+
return Object.getOwnPropertyDescriptor(cause, "method") !== undefined && Object.getOwnPropertyDescriptor(cause, "logs") !== undefined && (type === "error" || type === "closed" || type === "crashed");
|
|
14663
14908
|
}
|
|
14664
14909
|
function isBenignClosedSessionRejection(cause) {
|
|
14665
|
-
if (!(cause
|
|
14910
|
+
if (!isSafeHostError(cause))
|
|
14666
14911
|
return false;
|
|
14667
|
-
if (!isPatchrightProtocolError(cause) && !/patchright-core|playwright-core|coreBundle/.test(cause
|
|
14912
|
+
if (!isPatchrightProtocolError(cause) && !/patchright-core|playwright-core|coreBundle/.test(safeErrorStack(cause) ?? ""))
|
|
14668
14913
|
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
|
|
14914
|
+
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
14915
|
}
|
|
14671
14916
|
var benignRejections = { count: 0, logged: 0, lastLogAt: 0 };
|
|
14917
|
+
var unattributedRejections = { count: 0, logged: 0, lastLogAt: 0 };
|
|
14672
14918
|
function handleRelayProcessFault(kind, cause, detail, options = {}) {
|
|
14673
14919
|
if (kind === "unhandledRejection" && isBenignClosedSessionRejection(cause)) {
|
|
14674
14920
|
benignRejections.count += 1;
|
|
@@ -14677,31 +14923,46 @@ function handleRelayProcessFault(kind, cause, detail, options = {}) {
|
|
|
14677
14923
|
const since = benignRejections.count - benignRejections.logged;
|
|
14678
14924
|
benignRejections.lastLogAt = now;
|
|
14679
14925
|
benignRejections.logged = benignRejections.count;
|
|
14680
|
-
relayLog("process.benignRejections", { count: since, total: benignRejections.count, example: cause.
|
|
14926
|
+
relayLog("process.benignRejections", { count: since, total: benignRejections.count, example: safeErrorMessage(cause).slice(0, 160) });
|
|
14681
14927
|
}
|
|
14682
14928
|
return;
|
|
14683
14929
|
}
|
|
14684
14930
|
if (shouldSuppressRelayProcessFault(cause)) {
|
|
14685
14931
|
suppressedProcessFaults.count += 1;
|
|
14686
14932
|
suppressedProcessFaults.lastAt = new Date().toISOString();
|
|
14687
|
-
suppressedProcessFaults.lastMessage = (cause
|
|
14933
|
+
suppressedProcessFaults.lastMessage = safeErrorMessage(cause).slice(0, 300);
|
|
14688
14934
|
logProcessFault(kind, cause, detail, "keeping relay alive");
|
|
14689
14935
|
return;
|
|
14690
14936
|
}
|
|
14937
|
+
if (kind === "unhandledRejection") {
|
|
14938
|
+
const description = safeErrorMessage(cause);
|
|
14939
|
+
suppressedProcessFaults.count += 1;
|
|
14940
|
+
suppressedProcessFaults.lastAt = new Date().toISOString();
|
|
14941
|
+
suppressedProcessFaults.lastMessage = description.slice(0, 300);
|
|
14942
|
+
unattributedRejections.count += 1;
|
|
14943
|
+
const now = Date.now();
|
|
14944
|
+
if (description !== unattributedRejections.lastMessage || now - unattributedRejections.lastLogAt >= 60000) {
|
|
14945
|
+
const since = unattributedRejections.count - unattributedRejections.logged;
|
|
14946
|
+
unattributedRejections.lastLogAt = now;
|
|
14947
|
+
unattributedRejections.logged = unattributedRejections.count;
|
|
14948
|
+
unattributedRejections.lastMessage = description;
|
|
14949
|
+
logProcessFault(kind, cause, { suppressed: since }, "keeping relay alive; an unhandled rejection never stops the relay");
|
|
14950
|
+
}
|
|
14951
|
+
return;
|
|
14952
|
+
}
|
|
14691
14953
|
logProcessFault(kind, cause, detail, "not a known Playwright dispatch fault; rethrowing");
|
|
14692
14954
|
const rethrow = options.rethrow ?? rethrowProcessFault;
|
|
14693
14955
|
rethrow(cause);
|
|
14694
14956
|
}
|
|
14695
14957
|
function rethrowProcessFault(cause) {
|
|
14696
|
-
if (cause
|
|
14958
|
+
if (isSafeHostError(cause)) {
|
|
14697
14959
|
throw cause;
|
|
14698
14960
|
}
|
|
14699
|
-
throw new Error(
|
|
14961
|
+
throw new Error(safeErrorMessage(cause));
|
|
14700
14962
|
}
|
|
14701
14963
|
function logProcessFault(kind, cause, detail, disposition) {
|
|
14702
|
-
const errorText = cause instanceof Error ? cause.stack ?? cause.message : String(cause);
|
|
14703
14964
|
const message = `[browse relay] ${kind}; ${disposition}
|
|
14704
|
-
${
|
|
14965
|
+
${safeErrorStack(cause) ?? safeErrorMessage(cause)}`;
|
|
14705
14966
|
console.error(message);
|
|
14706
14967
|
if (process.env.OPENCODE_BROWSER_MANAGED_RELAY === "1")
|
|
14707
14968
|
appendManagedRelayProcessLog(message);
|
|
@@ -14712,6 +14973,30 @@ ${errorText}`;
|
|
|
14712
14973
|
function debugEnvironmentEnabled(value) {
|
|
14713
14974
|
return value !== undefined && ["1", "true", "yes", "on"].includes(value.toLowerCase());
|
|
14714
14975
|
}
|
|
14976
|
+
|
|
14977
|
+
// src/relay/process-guard.ts
|
|
14978
|
+
var installRelayProcessGuard = acquireRelease(sync2(() => {
|
|
14979
|
+
const onUncaughtException = (error, origin) => {
|
|
14980
|
+
if (handleExecuteRealmException(error))
|
|
14981
|
+
return;
|
|
14982
|
+
handleRelayProcessFault("uncaughtException", error, { origin });
|
|
14983
|
+
};
|
|
14984
|
+
const onUnhandledRejection = (reason, promise) => {
|
|
14985
|
+
if (handleExecuteRealmRejection(promise, reason)) {
|
|
14986
|
+
relayLog("process.executeRejection");
|
|
14987
|
+
return;
|
|
14988
|
+
}
|
|
14989
|
+
handleRelayProcessFault("unhandledRejection", reason, {});
|
|
14990
|
+
};
|
|
14991
|
+
process.on("uncaughtException", onUncaughtException);
|
|
14992
|
+
process.on("unhandledRejection", onUnhandledRejection);
|
|
14993
|
+
return { onUncaughtException, onUnhandledRejection };
|
|
14994
|
+
}), (handlers) => {
|
|
14995
|
+
return sync2(() => {
|
|
14996
|
+
process.off("uncaughtException", handlers.onUncaughtException);
|
|
14997
|
+
process.off("unhandledRejection", handlers.onUnhandledRejection);
|
|
14998
|
+
});
|
|
14999
|
+
});
|
|
14715
15000
|
function processAlive2(pid) {
|
|
14716
15001
|
try {
|
|
14717
15002
|
process.kill(pid, 0);
|
|
@@ -14812,49 +15097,6 @@ function createCdpDispatcher(options) {
|
|
|
14812
15097
|
});
|
|
14813
15098
|
return raceFirst(sendDebuggerCommand(command), nudges);
|
|
14814
15099
|
}
|
|
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
15100
|
const routeCdpCommand = fn("Relay.routeCdpCommand")(function* (socket, message) {
|
|
14859
15101
|
const clientOpenCodeBrowserSessionId = cdpClients.sessionId(socket);
|
|
14860
15102
|
if (!shutdownControl.accepting && (!cdpClients.isSandbox(socket) || !clientOpenCodeBrowserSessionId || !sessions.hasPendingWork(clientOpenCodeBrowserSessionId))) {
|
|
@@ -14958,7 +15200,7 @@ function createCdpDispatcher(options) {
|
|
|
14958
15200
|
}
|
|
14959
15201
|
if (message.method === "Target.createTarget" || message.method === "Target.closeTarget") {
|
|
14960
15202
|
if (message.method === "Target.createTarget") {
|
|
14961
|
-
const url =
|
|
15203
|
+
const url = createTargetUrl2(message.params);
|
|
14962
15204
|
const opencodeBrowserSessionId = cdpClients.sessionId(socket);
|
|
14963
15205
|
const autoAttachParams = cdpClients.autoAttachParams(socket);
|
|
14964
15206
|
const target = yield* createAndAttachTab({
|
|
@@ -15002,7 +15244,14 @@ function createCdpDispatcher(options) {
|
|
|
15002
15244
|
if (message.method === ghostCursorCommandMethod)
|
|
15003
15245
|
return yield* ghostCursor.command(tabId, message.params);
|
|
15004
15246
|
if (message.method === "Page.navigate" && route.chromeSessionId === undefined) {
|
|
15005
|
-
const dataNavigation = yield* navigateTopFrameToDataUrl(
|
|
15247
|
+
const dataNavigation = yield* navigateTopFrameToDataUrl({
|
|
15248
|
+
tabId,
|
|
15249
|
+
params: message.params,
|
|
15250
|
+
mainFrameIdsByTab,
|
|
15251
|
+
blankNavigationWaiters,
|
|
15252
|
+
registry,
|
|
15253
|
+
sendDebuggerCommand
|
|
15254
|
+
});
|
|
15006
15255
|
if (dataNavigation)
|
|
15007
15256
|
return dataNavigation;
|
|
15008
15257
|
}
|
|
@@ -17119,6 +17368,7 @@ class SessionNavigationGuard {
|
|
|
17119
17368
|
warnings = new Map;
|
|
17120
17369
|
rulesCache = new Map;
|
|
17121
17370
|
freshPopups = new Set;
|
|
17371
|
+
blanking = new Map;
|
|
17122
17372
|
constructor(dependencies) {
|
|
17123
17373
|
this.dependencies = dependencies;
|
|
17124
17374
|
}
|
|
@@ -17148,7 +17398,7 @@ class SessionNavigationGuard {
|
|
|
17148
17398
|
const rules = this.rules(options.sessionId);
|
|
17149
17399
|
if (!rules)
|
|
17150
17400
|
return;
|
|
17151
|
-
const url =
|
|
17401
|
+
const url = options.method === "Target.createTarget" ? createTargetUrl2(options.params) : getString2(options.params, "url");
|
|
17152
17402
|
if (url === undefined)
|
|
17153
17403
|
return;
|
|
17154
17404
|
const decision = await checkNavigationUrl(url, rules);
|
|
@@ -17163,8 +17413,16 @@ class SessionNavigationGuard {
|
|
|
17163
17413
|
this.freshPopups.add(target.tabId);
|
|
17164
17414
|
this.observeCommittedUrl(target, target.targetInfo.url);
|
|
17165
17415
|
}
|
|
17416
|
+
createdTabNavigated(target) {
|
|
17417
|
+
if (!this.enforced(target))
|
|
17418
|
+
return true;
|
|
17419
|
+
if ((this.blanking.get(target.tabId) ?? 0) > 0)
|
|
17420
|
+
return false;
|
|
17421
|
+
return this.observeCommittedUrl(target, target.targetInfo.url);
|
|
17422
|
+
}
|
|
17166
17423
|
forgetTab(tabId) {
|
|
17167
17424
|
this.freshPopups.delete(tabId);
|
|
17425
|
+
this.blanking.delete(tabId);
|
|
17168
17426
|
}
|
|
17169
17427
|
observeEvent(target, method, params) {
|
|
17170
17428
|
if (method !== "Page.frameNavigated" && method !== "Page.frameRequestedNavigation" && method !== "Page.frameStartedNavigating" && method !== "Network.responseReceived")
|
|
@@ -17215,14 +17473,15 @@ class SessionNavigationGuard {
|
|
|
17215
17473
|
observeCommittedUrl(target, url) {
|
|
17216
17474
|
const rules = this.rules(target.opencodeBrowserSessionId);
|
|
17217
17475
|
if (!rules)
|
|
17218
|
-
return;
|
|
17476
|
+
return true;
|
|
17219
17477
|
const decision = checkUrl(url, rules);
|
|
17220
17478
|
if (decision.allowed) {
|
|
17221
17479
|
if (!/^about:/.test(url))
|
|
17222
17480
|
this.freshPopups.delete(target.tabId);
|
|
17223
|
-
return;
|
|
17481
|
+
return true;
|
|
17224
17482
|
}
|
|
17225
17483
|
this.violation(target, url, decision.reason, "commit");
|
|
17484
|
+
return false;
|
|
17226
17485
|
}
|
|
17227
17486
|
violation(target, url, reason, _stage) {
|
|
17228
17487
|
const sessionId = target.opencodeBrowserSessionId;
|
|
@@ -17238,7 +17497,14 @@ class SessionNavigationGuard {
|
|
|
17238
17497
|
});
|
|
17239
17498
|
return;
|
|
17240
17499
|
}
|
|
17241
|
-
this.
|
|
17500
|
+
this.blanking.set(target.tabId, (this.blanking.get(target.tabId) ?? 0) + 1);
|
|
17501
|
+
this.dependencies.send(target.tabId, "Page.stopLoading", {}).catch(() => {}).then(() => this.dependencies.send(target.tabId, "Page.navigate", { url: "about:blank" })).catch(() => {}).finally(() => {
|
|
17502
|
+
const remaining = (this.blanking.get(target.tabId) ?? 1) - 1;
|
|
17503
|
+
if (remaining > 0)
|
|
17504
|
+
this.blanking.set(target.tabId, remaining);
|
|
17505
|
+
else
|
|
17506
|
+
this.blanking.delete(target.tabId);
|
|
17507
|
+
});
|
|
17242
17508
|
}
|
|
17243
17509
|
addWarning(sessionId, warning) {
|
|
17244
17510
|
const pending = this.warnings.get(sessionId) ?? [];
|
|
@@ -17626,17 +17892,38 @@ var makeRelay = fnUntraced(function* (options = {}) {
|
|
|
17626
17892
|
});
|
|
17627
17893
|
const createAndAttachTab = fnUntraced(function* (createOptions) {
|
|
17628
17894
|
const link = yield* sessionBrowser(createOptions.opencodeBrowserSessionId);
|
|
17629
|
-
const result = yield* sendToExtension({ method: "tabs.create", params: { url:
|
|
17895
|
+
const result = yield* sendToExtension({ method: "tabs.create", params: { url: "about:blank", active: createOptions.active, ...agentWindow ? { window: agentWindow } : {} } }, link);
|
|
17630
17896
|
const tabId = getNumber2(result, "tabId");
|
|
17631
17897
|
if (!tabId)
|
|
17632
17898
|
return yield* fail5(new Error("tabs.create did not return a tabId"));
|
|
17633
17899
|
announceTab(tabId);
|
|
17634
|
-
|
|
17900
|
+
const target = yield* rootLifecycle.attach({
|
|
17635
17901
|
tabId,
|
|
17636
17902
|
owner: "relay",
|
|
17637
17903
|
...createOptions.opencodeBrowserSessionId ? { opencodeBrowserSessionId: createOptions.opencodeBrowserSessionId } : {},
|
|
17638
17904
|
...createOptions.autoAttachParams ? { autoAttachParams: createOptions.autoAttachParams } : {}
|
|
17639
17905
|
});
|
|
17906
|
+
const requested = createTargetUrl2({ url: createOptions.url });
|
|
17907
|
+
if (requested !== "about:blank") {
|
|
17908
|
+
const data = /^data:/i.test(requested.trim());
|
|
17909
|
+
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(() => {
|
|
17910
|
+
relayLog("create.navigate-failed", { tabId, error: error instanceof Error ? error.message : String(error) });
|
|
17911
|
+
return;
|
|
17912
|
+
})));
|
|
17913
|
+
const errorText = getString2(navigation, "errorText");
|
|
17914
|
+
if (errorText)
|
|
17915
|
+
relayLog("create.navigate-failed", { tabId, errorText });
|
|
17916
|
+
else if (data && navigation === undefined)
|
|
17917
|
+
relayLog("create.data-skipped", { tabId });
|
|
17918
|
+
const current = yield* sendDebuggerCommand({ tabId, method: "Target.getTargetInfo", params: {} }).pipe(orElseSucceed(() => ({})));
|
|
17919
|
+
const targetInfo = getTargetInfo2(current.targetInfo);
|
|
17920
|
+
if (targetInfo && !isRestrictedTarget2(targetInfo) && navigationGuard.createdTabNavigated({ ...target, targetInfo })) {
|
|
17921
|
+
const updated = registry.updateConnectedTargetInfo({ tabId, targetInfo });
|
|
17922
|
+
if (updated?.kind === "root")
|
|
17923
|
+
return updated.target;
|
|
17924
|
+
}
|
|
17925
|
+
}
|
|
17926
|
+
return target;
|
|
17640
17927
|
});
|
|
17641
17928
|
const closeTargetByTargetId = fnUntraced(function* (targetId) {
|
|
17642
17929
|
const target = registry.targetsByTargetId.get(targetId);
|