@ricsam/isolate 0.1.8 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +172 -18
- package/dist/cjs/bridge/diagnostics.cjs +37 -2
- package/dist/cjs/bridge/diagnostics.cjs.map +3 -3
- package/dist/cjs/bridge/runtime-bindings.cjs +203 -51
- package/dist/cjs/bridge/runtime-bindings.cjs.map +3 -3
- package/dist/cjs/bridge/sandbox-isolate.cjs +365 -0
- package/dist/cjs/bridge/sandbox-isolate.cjs.map +10 -0
- package/dist/cjs/host/create-isolate-host.cjs +51 -25
- package/dist/cjs/host/create-isolate-host.cjs.map +3 -3
- package/dist/cjs/host/nested-host-controller.cjs +311 -0
- package/dist/cjs/host/nested-host-controller.cjs.map +10 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/internal/browser-source.cjs +91 -0
- package/dist/cjs/internal/browser-source.cjs.map +10 -0
- package/dist/cjs/internal/client/connection.cjs +152 -172
- package/dist/cjs/internal/client/connection.cjs.map +3 -3
- package/dist/cjs/internal/daemon/callback-fs-handler.cjs +3 -3
- package/dist/cjs/internal/daemon/callback-fs-handler.cjs.map +3 -3
- package/dist/cjs/internal/daemon/connection.cjs +129 -4
- package/dist/cjs/internal/daemon/connection.cjs.map +3 -3
- package/dist/cjs/internal/encoding/index.cjs +27 -4
- package/dist/cjs/internal/encoding/index.cjs.map +3 -3
- package/dist/cjs/internal/fetch/index.cjs +2 -7
- package/dist/cjs/internal/fetch/index.cjs.map +3 -3
- package/dist/cjs/internal/module-loader/bundle.cjs +128 -1
- package/dist/cjs/internal/module-loader/bundle.cjs.map +3 -3
- package/dist/cjs/internal/playwright/client.cjs +4 -2
- package/dist/cjs/internal/playwright/client.cjs.map +3 -3
- package/dist/cjs/internal/playwright/handler.cjs +298 -25
- package/dist/cjs/internal/playwright/handler.cjs.map +3 -3
- package/dist/cjs/internal/playwright/index.cjs +54 -8
- package/dist/cjs/internal/playwright/index.cjs.map +3 -3
- package/dist/cjs/internal/playwright/types.cjs +3 -1
- package/dist/cjs/internal/playwright/types.cjs.map +3 -3
- package/dist/cjs/internal/protocol/codec.cjs +16 -5
- package/dist/cjs/internal/protocol/codec.cjs.map +3 -3
- package/dist/cjs/internal/protocol/marshalValue.cjs +37 -6
- package/dist/cjs/internal/protocol/marshalValue.cjs.map +3 -3
- package/dist/cjs/internal/protocol/types.cjs.map +2 -2
- package/dist/cjs/internal/runtime/index.cjs +377 -22
- package/dist/cjs/internal/runtime/index.cjs.map +3 -3
- package/dist/cjs/internal/typecheck/index.cjs +2 -1
- package/dist/cjs/internal/typecheck/index.cjs.map +3 -3
- package/dist/cjs/internal/typecheck/isolate-types.cjs +186 -13
- package/dist/cjs/internal/typecheck/isolate-types.cjs.map +3 -3
- package/dist/cjs/internal/typecheck/typecheck.cjs +2 -3
- package/dist/cjs/internal/typecheck/typecheck.cjs.map +3 -3
- package/dist/cjs/modules/index.cjs +6 -1
- package/dist/cjs/modules/index.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/runtime/script-runtime.cjs +14 -12
- package/dist/cjs/runtime/script-runtime.cjs.map +3 -3
- package/dist/cjs/runtime/test-runtime.cjs +113 -0
- package/dist/cjs/runtime/test-runtime.cjs.map +10 -0
- package/dist/cjs/server/app-server.cjs +16 -9
- package/dist/cjs/server/app-server.cjs.map +3 -3
- package/dist/cjs/typecheck/index.cjs +2 -1
- package/dist/cjs/typecheck/index.cjs.map +3 -3
- package/dist/mjs/bridge/diagnostics.mjs +37 -2
- package/dist/mjs/bridge/diagnostics.mjs.map +3 -3
- package/dist/mjs/bridge/runtime-bindings.mjs +206 -51
- package/dist/mjs/bridge/runtime-bindings.mjs.map +3 -3
- package/dist/mjs/bridge/sandbox-isolate.mjs +325 -0
- package/dist/mjs/bridge/sandbox-isolate.mjs.map +10 -0
- package/dist/mjs/host/create-isolate-host.mjs +53 -25
- package/dist/mjs/host/create-isolate-host.mjs.map +3 -3
- package/dist/mjs/host/nested-host-controller.mjs +275 -0
- package/dist/mjs/host/nested-host-controller.mjs.map +10 -0
- package/dist/mjs/index.mjs.map +1 -1
- package/dist/mjs/internal/browser-source.mjs +51 -0
- package/dist/mjs/internal/browser-source.mjs.map +10 -0
- package/dist/mjs/internal/client/connection.mjs +154 -173
- package/dist/mjs/internal/client/connection.mjs.map +3 -3
- package/dist/mjs/internal/daemon/callback-fs-handler.mjs +3 -3
- package/dist/mjs/internal/daemon/callback-fs-handler.mjs.map +3 -3
- package/dist/mjs/internal/daemon/connection.mjs +129 -4
- package/dist/mjs/internal/daemon/connection.mjs.map +3 -3
- package/dist/mjs/internal/encoding/index.mjs +27 -4
- package/dist/mjs/internal/encoding/index.mjs.map +3 -3
- package/dist/mjs/internal/fetch/index.mjs +2 -7
- package/dist/mjs/internal/fetch/index.mjs.map +3 -3
- package/dist/mjs/internal/module-loader/bundle.mjs +129 -2
- package/dist/mjs/internal/module-loader/bundle.mjs.map +3 -3
- package/dist/mjs/internal/playwright/client.mjs +7 -3
- package/dist/mjs/internal/playwright/client.mjs.map +3 -3
- package/dist/mjs/internal/playwright/handler.mjs +300 -26
- package/dist/mjs/internal/playwright/handler.mjs.map +3 -3
- package/dist/mjs/internal/playwright/index.mjs +59 -9
- package/dist/mjs/internal/playwright/index.mjs.map +3 -3
- package/dist/mjs/internal/playwright/types.mjs +3 -1
- package/dist/mjs/internal/playwright/types.mjs.map +3 -3
- package/dist/mjs/internal/protocol/codec.mjs +16 -5
- package/dist/mjs/internal/protocol/codec.mjs.map +3 -3
- package/dist/mjs/internal/protocol/marshalValue.mjs +38 -6
- package/dist/mjs/internal/protocol/marshalValue.mjs.map +3 -3
- package/dist/mjs/internal/protocol/types.mjs.map +2 -2
- package/dist/mjs/internal/runtime/index.mjs +377 -22
- package/dist/mjs/internal/runtime/index.mjs.map +3 -3
- package/dist/mjs/internal/typecheck/index.mjs +3 -1
- package/dist/mjs/internal/typecheck/index.mjs.map +3 -3
- package/dist/mjs/internal/typecheck/isolate-types.mjs +186 -13
- package/dist/mjs/internal/typecheck/isolate-types.mjs.map +3 -3
- package/dist/mjs/internal/typecheck/typecheck.mjs +2 -3
- package/dist/mjs/internal/typecheck/typecheck.mjs.map +3 -3
- package/dist/mjs/modules/index.mjs +6 -1
- package/dist/mjs/modules/index.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/runtime/script-runtime.mjs +16 -12
- package/dist/mjs/runtime/script-runtime.mjs.map +3 -3
- package/dist/mjs/runtime/test-runtime.mjs +78 -0
- package/dist/mjs/runtime/test-runtime.mjs.map +10 -0
- package/dist/mjs/server/app-server.mjs +23 -11
- package/dist/mjs/server/app-server.mjs.map +3 -3
- package/dist/mjs/typecheck/index.mjs +2 -1
- package/dist/mjs/typecheck/index.mjs.map +3 -3
- package/dist/types/bridge/diagnostics.d.ts +6 -1
- package/dist/types/bridge/runtime-bindings.d.ts +5 -1
- package/dist/types/bridge/sandbox-isolate.d.ts +15 -0
- package/dist/types/host/nested-host-controller.d.ts +11 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internal/browser-source.d.ts +11 -0
- package/dist/types/internal/client/types.d.ts +5 -0
- package/dist/types/internal/daemon/types.d.ts +0 -2
- package/dist/types/internal/playwright/client.d.ts +2 -2
- package/dist/types/internal/playwright/handler.d.ts +27 -4
- package/dist/types/internal/playwright/index.d.ts +2 -2
- package/dist/types/internal/playwright/types.d.ts +33 -1
- package/dist/types/internal/protocol/codec.d.ts +12 -2
- package/dist/types/internal/protocol/marshalValue.d.ts +3 -2
- package/dist/types/internal/protocol/types.d.ts +25 -1
- package/dist/types/internal/runtime/index.d.ts +5 -0
- package/dist/types/internal/typecheck/index.d.ts +1 -1
- package/dist/types/internal/typecheck/isolate-types.d.ts +6 -4
- package/dist/types/internal/typecheck/typecheck.d.ts +1 -1
- package/dist/types/runtime/script-runtime.d.ts +2 -1
- package/dist/types/runtime/test-runtime.d.ts +4 -0
- package/dist/types/server/app-server.d.ts +2 -1
- package/dist/types/types.d.ts +33 -33
- package/package.json +3 -3
- package/dist/cjs/browser/browser-runtime.cjs +0 -157
- package/dist/cjs/browser/browser-runtime.cjs.map +0 -10
- package/dist/mjs/browser/browser-runtime.mjs +0 -93
- package/dist/mjs/browser/browser-runtime.mjs.map +0 -10
- package/dist/types/browser/browser-runtime.d.ts +0 -3
|
@@ -20,7 +20,8 @@ import {
|
|
|
20
20
|
} from "../protocol/index.mjs";
|
|
21
21
|
import {
|
|
22
22
|
defaultPlaywrightHandler,
|
|
23
|
-
getDefaultPlaywrightHandlerMetadata
|
|
23
|
+
getDefaultPlaywrightHandlerMetadata,
|
|
24
|
+
getPlaywrightHandlerMetadata
|
|
24
25
|
} from "../playwright/client.mjs";
|
|
25
26
|
var isolateWsCallbacks = new Map;
|
|
26
27
|
var isolateClientWebSockets = new Map;
|
|
@@ -44,8 +45,13 @@ async function connect(options = {}) {
|
|
|
44
45
|
callbackStreamReaders: new Map,
|
|
45
46
|
activeCallbackInvocations: new Map,
|
|
46
47
|
callbackAbortControllers: new Map,
|
|
48
|
+
clientIteratorSessions: new Map,
|
|
49
|
+
returnedPromiseRegistry: new Map,
|
|
50
|
+
returnedIteratorRegistry: new Map,
|
|
47
51
|
closing: false,
|
|
48
|
-
namespacedRuntimes: new Map
|
|
52
|
+
namespacedRuntimes: new Map,
|
|
53
|
+
nextClientIteratorId: 1,
|
|
54
|
+
nextReturnedRefId: 1
|
|
49
55
|
};
|
|
50
56
|
function setupSocket(sock) {
|
|
51
57
|
const parser = createFrameParser();
|
|
@@ -89,6 +95,9 @@ async function connect(options = {}) {
|
|
|
89
95
|
}
|
|
90
96
|
state.callbackAbortControllers.clear();
|
|
91
97
|
state.activeCallbackInvocations.clear();
|
|
98
|
+
state.clientIteratorSessions.clear();
|
|
99
|
+
state.returnedPromiseRegistry.clear();
|
|
100
|
+
state.returnedIteratorRegistry.clear();
|
|
92
101
|
if (!state.closing && state.namespacedRuntimes.size > 0) {
|
|
93
102
|
state.reconnecting = reconnect(state, options).catch(() => {
|
|
94
103
|
state.namespacedRuntimes.clear();
|
|
@@ -609,145 +618,57 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
609
618
|
callbacks.custom = registerCustomFunctions(state, options.customFunctions);
|
|
610
619
|
}
|
|
611
620
|
let playwrightHandler;
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
621
|
+
let getCollectedData = () => ({
|
|
622
|
+
browserConsoleLogs: [],
|
|
623
|
+
pageErrors: [],
|
|
624
|
+
networkRequests: [],
|
|
625
|
+
networkResponses: [],
|
|
626
|
+
requestFailures: []
|
|
627
|
+
});
|
|
628
|
+
let getTrackedResources = () => ({
|
|
629
|
+
contexts: [],
|
|
630
|
+
pages: []
|
|
631
|
+
});
|
|
632
|
+
let clearCollectedData = () => {};
|
|
633
|
+
const playwrightListenerCleanups = [];
|
|
618
634
|
if (normalizedPlaywrightOptions) {
|
|
619
635
|
playwrightHandler = normalizedPlaywrightOptions.handler;
|
|
620
636
|
if (!playwrightHandler) {
|
|
621
637
|
throw new Error("playwright.handler is required when using playwright options");
|
|
622
638
|
}
|
|
623
|
-
const
|
|
639
|
+
const handlerMetadata = getPlaywrightHandlerMetadata(playwrightHandler);
|
|
640
|
+
if (handlerMetadata) {
|
|
641
|
+
getCollectedData = () => handlerMetadata.collector.getCollectedData();
|
|
642
|
+
getTrackedResources = () => handlerMetadata.collector.getTrackedResources();
|
|
643
|
+
clearCollectedData = () => {
|
|
644
|
+
handlerMetadata.collector.clearCollectedData();
|
|
645
|
+
};
|
|
646
|
+
playwrightListenerCleanups.push(handlerMetadata.collector.onEvent((event) => {
|
|
647
|
+
if (normalizedPlaywrightOptions.onEvent) {
|
|
648
|
+
normalizedPlaywrightOptions.onEvent(event);
|
|
649
|
+
}
|
|
650
|
+
if (event.type === "browserConsoleLog") {
|
|
651
|
+
if (normalizedPlaywrightOptions.console && options.console?.onEntry) {
|
|
652
|
+
options.console.onEntry({
|
|
653
|
+
type: "browserOutput",
|
|
654
|
+
level: event.level,
|
|
655
|
+
stdout: event.stdout,
|
|
656
|
+
location: event.location,
|
|
657
|
+
timestamp: event.timestamp
|
|
658
|
+
});
|
|
659
|
+
} else if (normalizedPlaywrightOptions.console) {
|
|
660
|
+
const prefix = event.level === "error" ? "[browser:error]" : "[browser]";
|
|
661
|
+
console.log(prefix, event.stdout);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}));
|
|
665
|
+
}
|
|
624
666
|
const handlerCallbackId = state.nextCallbackId++;
|
|
625
667
|
state.callbacks.set(handlerCallbackId, async (opJson) => {
|
|
626
668
|
const op = JSON.parse(opJson);
|
|
627
669
|
const result2 = await playwrightHandler(op);
|
|
628
670
|
return JSON.stringify(result2);
|
|
629
671
|
});
|
|
630
|
-
if (page) {
|
|
631
|
-
const requestIds = new WeakMap;
|
|
632
|
-
let nextRequestId = 1;
|
|
633
|
-
const getRequestId = (request2) => {
|
|
634
|
-
let requestId2 = requestIds.get(request2);
|
|
635
|
-
if (!requestId2) {
|
|
636
|
-
requestId2 = `req_${nextRequestId++}`;
|
|
637
|
-
requestIds.set(request2, requestId2);
|
|
638
|
-
}
|
|
639
|
-
return requestId2;
|
|
640
|
-
};
|
|
641
|
-
const toLocation = (location) => {
|
|
642
|
-
if (!location || !location.url && location.lineNumber == null && location.columnNumber == null) {
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
return {
|
|
646
|
-
url: location.url || undefined,
|
|
647
|
-
lineNumber: location.lineNumber != null ? location.lineNumber + 1 : undefined,
|
|
648
|
-
columnNumber: location.columnNumber != null ? location.columnNumber + 1 : undefined
|
|
649
|
-
};
|
|
650
|
-
};
|
|
651
|
-
const onConsole = (msg) => {
|
|
652
|
-
const entry = {
|
|
653
|
-
level: msg.type(),
|
|
654
|
-
stdout: msg.text(),
|
|
655
|
-
location: toLocation(msg.location()),
|
|
656
|
-
timestamp: Date.now()
|
|
657
|
-
};
|
|
658
|
-
browserConsoleLogs.push(entry);
|
|
659
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
660
|
-
normalizedPlaywrightOptions.onEvent({
|
|
661
|
-
type: "browserConsoleLog",
|
|
662
|
-
...entry
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
if (normalizedPlaywrightOptions.console && options.console?.onEntry) {
|
|
666
|
-
options.console.onEntry({
|
|
667
|
-
type: "browserOutput",
|
|
668
|
-
...entry
|
|
669
|
-
});
|
|
670
|
-
} else if (normalizedPlaywrightOptions.console) {
|
|
671
|
-
const prefix = entry.level === "error" ? "[browser:error]" : "[browser]";
|
|
672
|
-
console.log(prefix, entry.stdout);
|
|
673
|
-
}
|
|
674
|
-
};
|
|
675
|
-
const onRequest = (request2) => {
|
|
676
|
-
const info = {
|
|
677
|
-
requestId: getRequestId(request2),
|
|
678
|
-
url: request2.url(),
|
|
679
|
-
method: request2.method(),
|
|
680
|
-
headers: request2.headers(),
|
|
681
|
-
postData: request2.postData() ?? undefined,
|
|
682
|
-
resourceType: request2.resourceType(),
|
|
683
|
-
timestamp: Date.now()
|
|
684
|
-
};
|
|
685
|
-
networkRequests.push(info);
|
|
686
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
687
|
-
normalizedPlaywrightOptions.onEvent({
|
|
688
|
-
type: "networkRequest",
|
|
689
|
-
...info
|
|
690
|
-
});
|
|
691
|
-
}
|
|
692
|
-
};
|
|
693
|
-
const onResponse = (response) => {
|
|
694
|
-
const request2 = response.request();
|
|
695
|
-
const info = {
|
|
696
|
-
requestId: getRequestId(request2),
|
|
697
|
-
url: response.url(),
|
|
698
|
-
status: response.status(),
|
|
699
|
-
statusText: response.statusText(),
|
|
700
|
-
headers: response.headers(),
|
|
701
|
-
resourceType: request2.resourceType(),
|
|
702
|
-
timestamp: Date.now()
|
|
703
|
-
};
|
|
704
|
-
networkResponses.push(info);
|
|
705
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
706
|
-
normalizedPlaywrightOptions.onEvent({
|
|
707
|
-
type: "networkResponse",
|
|
708
|
-
...info
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
};
|
|
712
|
-
const onRequestFailed = (request2) => {
|
|
713
|
-
const info = {
|
|
714
|
-
requestId: getRequestId(request2),
|
|
715
|
-
url: request2.url(),
|
|
716
|
-
method: request2.method(),
|
|
717
|
-
failureText: request2.failure()?.errorText || "request failed",
|
|
718
|
-
resourceType: request2.resourceType(),
|
|
719
|
-
timestamp: Date.now()
|
|
720
|
-
};
|
|
721
|
-
requestFailures.push(info);
|
|
722
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
723
|
-
normalizedPlaywrightOptions.onEvent({
|
|
724
|
-
type: "requestFailure",
|
|
725
|
-
...info
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
};
|
|
729
|
-
const onPageError = (error) => {
|
|
730
|
-
const entry = {
|
|
731
|
-
name: error.name,
|
|
732
|
-
message: error.message,
|
|
733
|
-
stack: error.stack,
|
|
734
|
-
timestamp: Date.now()
|
|
735
|
-
};
|
|
736
|
-
pageErrors.push(entry);
|
|
737
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
738
|
-
normalizedPlaywrightOptions.onEvent({
|
|
739
|
-
type: "pageError",
|
|
740
|
-
...entry
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
};
|
|
744
|
-
page.on("console", onConsole);
|
|
745
|
-
page.on("request", onRequest);
|
|
746
|
-
page.on("response", onResponse);
|
|
747
|
-
page.on("requestfailed", onRequestFailed);
|
|
748
|
-
page.on("pageerror", onPageError);
|
|
749
|
-
pageListenerCleanups.push(() => page.removeListener("console", onConsole), () => page.removeListener("request", onRequest), () => page.removeListener("response", onResponse), () => page.removeListener("requestfailed", onRequestFailed), () => page.removeListener("pageerror", onPageError));
|
|
750
|
-
}
|
|
751
672
|
callbacks.playwright = {
|
|
752
673
|
handlerCallbackId,
|
|
753
674
|
console: normalizedPlaywrightOptions.console && !options.console?.onEntry
|
|
@@ -778,7 +699,10 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
778
699
|
testEnvironmentOption = true;
|
|
779
700
|
}
|
|
780
701
|
}
|
|
781
|
-
const playwrightOption = normalizedPlaywrightOptions
|
|
702
|
+
const playwrightOption = normalizedPlaywrightOptions ? {
|
|
703
|
+
timeout: normalizedPlaywrightOptions.timeout,
|
|
704
|
+
hasDefaultPage: normalizedPlaywrightOptions.hasDefaultPage
|
|
705
|
+
} : undefined;
|
|
782
706
|
const requestId = state.nextRequestId++;
|
|
783
707
|
const request = {
|
|
784
708
|
type: MessageType.CREATE_RUNTIME,
|
|
@@ -1089,23 +1013,19 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
1089
1013
|
if (!playwrightEnabled) {
|
|
1090
1014
|
throw new Error("Playwright not configured. Provide playwright.handler in createRuntime options.");
|
|
1091
1015
|
}
|
|
1092
|
-
return
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1016
|
+
return getCollectedData();
|
|
1017
|
+
},
|
|
1018
|
+
getTrackedResources() {
|
|
1019
|
+
if (!playwrightEnabled) {
|
|
1020
|
+
throw new Error("Playwright not configured. Provide playwright.handler in createRuntime options.");
|
|
1021
|
+
}
|
|
1022
|
+
return getTrackedResources();
|
|
1099
1023
|
},
|
|
1100
1024
|
clearCollectedData() {
|
|
1101
1025
|
if (!playwrightEnabled) {
|
|
1102
1026
|
throw new Error("Playwright not configured. Provide playwright.handler in createRuntime options.");
|
|
1103
1027
|
}
|
|
1104
|
-
|
|
1105
|
-
pageErrors.length = 0;
|
|
1106
|
-
networkRequests.length = 0;
|
|
1107
|
-
networkResponses.length = 0;
|
|
1108
|
-
requestFailures.length = 0;
|
|
1028
|
+
clearCollectedData();
|
|
1109
1029
|
}
|
|
1110
1030
|
};
|
|
1111
1031
|
return {
|
|
@@ -1160,7 +1080,7 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
1160
1080
|
});
|
|
1161
1081
|
},
|
|
1162
1082
|
dispose: async (options2) => {
|
|
1163
|
-
for (const cleanup of
|
|
1083
|
+
for (const cleanup of playwrightListenerCleanups) {
|
|
1164
1084
|
cleanup();
|
|
1165
1085
|
}
|
|
1166
1086
|
isolateWsCallbacks.delete(isolateId);
|
|
@@ -1404,10 +1324,6 @@ function registerModuleLoaderCallback(state, callback) {
|
|
|
1404
1324
|
});
|
|
1405
1325
|
return { callbackId, name: "moduleLoader", type: "async" };
|
|
1406
1326
|
}
|
|
1407
|
-
var clientIteratorSessions = new Map;
|
|
1408
|
-
var nextClientIteratorId = 1;
|
|
1409
|
-
var returnedPromiseRegistry = new Map;
|
|
1410
|
-
var returnedIteratorRegistry = new Map;
|
|
1411
1327
|
function registerCustomFunctions(state, customFunctions) {
|
|
1412
1328
|
const registrations = {};
|
|
1413
1329
|
const addCallbackIdsToRefs = (value) => {
|
|
@@ -1418,12 +1334,12 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1418
1334
|
const resolveCallbackId = state.nextCallbackId++;
|
|
1419
1335
|
state.callbacks.set(resolveCallbackId, async (...args) => {
|
|
1420
1336
|
const promiseId = args[0];
|
|
1421
|
-
const promise = returnedPromiseRegistry.get(promiseId);
|
|
1337
|
+
const promise = state.returnedPromiseRegistry.get(promiseId);
|
|
1422
1338
|
if (!promise) {
|
|
1423
1339
|
throw new Error(`Promise ${promiseId} not found`);
|
|
1424
1340
|
}
|
|
1425
1341
|
const promiseResult = await promise;
|
|
1426
|
-
returnedPromiseRegistry.delete(promiseId);
|
|
1342
|
+
state.returnedPromiseRegistry.delete(promiseId);
|
|
1427
1343
|
const marshalledResult = await marshalValue(promiseResult, marshalCtx);
|
|
1428
1344
|
return addCallbackIdsToRefs(marshalledResult);
|
|
1429
1345
|
});
|
|
@@ -1436,13 +1352,13 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1436
1352
|
const nextCallbackId = state.nextCallbackId++;
|
|
1437
1353
|
state.callbacks.set(nextCallbackId, async (...args) => {
|
|
1438
1354
|
const iteratorId = args[0];
|
|
1439
|
-
const iterator = returnedIteratorRegistry.get(iteratorId);
|
|
1355
|
+
const iterator = state.returnedIteratorRegistry.get(iteratorId);
|
|
1440
1356
|
if (!iterator) {
|
|
1441
1357
|
throw new Error(`Iterator ${iteratorId} not found`);
|
|
1442
1358
|
}
|
|
1443
1359
|
const iterResult = await iterator.next();
|
|
1444
1360
|
if (iterResult.done) {
|
|
1445
|
-
returnedIteratorRegistry.delete(iteratorId);
|
|
1361
|
+
state.returnedIteratorRegistry.delete(iteratorId);
|
|
1446
1362
|
}
|
|
1447
1363
|
const marshalledValue = await marshalValue(iterResult.value, marshalCtx);
|
|
1448
1364
|
return {
|
|
@@ -1454,8 +1370,8 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1454
1370
|
state.callbacks.set(returnCallbackId, async (...args) => {
|
|
1455
1371
|
const iteratorId = args[0];
|
|
1456
1372
|
const returnValue = args[1];
|
|
1457
|
-
const iterator = returnedIteratorRegistry.get(iteratorId);
|
|
1458
|
-
returnedIteratorRegistry.delete(iteratorId);
|
|
1373
|
+
const iterator = state.returnedIteratorRegistry.get(iteratorId);
|
|
1374
|
+
state.returnedIteratorRegistry.delete(iteratorId);
|
|
1459
1375
|
if (!iterator || !iterator.return) {
|
|
1460
1376
|
return { done: true, value: undefined };
|
|
1461
1377
|
}
|
|
@@ -1470,7 +1386,7 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1470
1386
|
state.callbacks.set(throwCallbackId, async (...args) => {
|
|
1471
1387
|
const iteratorId = args[0];
|
|
1472
1388
|
const errorValue = args[1];
|
|
1473
|
-
const iterator = returnedIteratorRegistry.get(iteratorId);
|
|
1389
|
+
const iterator = state.returnedIteratorRegistry.get(iteratorId);
|
|
1474
1390
|
if (!iterator) {
|
|
1475
1391
|
throw new Error(`Iterator ${iteratorId} not found`);
|
|
1476
1392
|
}
|
|
@@ -1481,7 +1397,7 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1481
1397
|
const thrownError = Object.assign(new Error(errorValue?.message ?? "Iterator throw()"), { name: errorValue?.name ?? "Error", stack: errorValue?.stack });
|
|
1482
1398
|
const iterResult = await iterator.throw(thrownError);
|
|
1483
1399
|
if (iterResult.done) {
|
|
1484
|
-
returnedIteratorRegistry.delete(iteratorId);
|
|
1400
|
+
state.returnedIteratorRegistry.delete(iteratorId);
|
|
1485
1401
|
}
|
|
1486
1402
|
const marshalledValue = await marshalValue(iterResult.value, marshalCtx);
|
|
1487
1403
|
return {
|
|
@@ -1489,7 +1405,7 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1489
1405
|
value: addCallbackIdsToRefs(marshalledValue)
|
|
1490
1406
|
};
|
|
1491
1407
|
} catch (error) {
|
|
1492
|
-
returnedIteratorRegistry.delete(iteratorId);
|
|
1408
|
+
state.returnedIteratorRegistry.delete(iteratorId);
|
|
1493
1409
|
throw error;
|
|
1494
1410
|
}
|
|
1495
1411
|
});
|
|
@@ -1520,13 +1436,13 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1520
1436
|
return returnedCallbackId;
|
|
1521
1437
|
},
|
|
1522
1438
|
registerPromise: (promise) => {
|
|
1523
|
-
const promiseId = state.
|
|
1524
|
-
returnedPromiseRegistry.set(promiseId, promise);
|
|
1439
|
+
const promiseId = state.nextReturnedRefId++;
|
|
1440
|
+
state.returnedPromiseRegistry.set(promiseId, promise);
|
|
1525
1441
|
return promiseId;
|
|
1526
1442
|
},
|
|
1527
1443
|
registerIterator: (iterator) => {
|
|
1528
|
-
const iteratorId = state.
|
|
1529
|
-
returnedIteratorRegistry.set(iteratorId, iterator);
|
|
1444
|
+
const iteratorId = state.nextReturnedRefId++;
|
|
1445
|
+
state.returnedIteratorRegistry.set(iteratorId, iterator);
|
|
1530
1446
|
return iteratorId;
|
|
1531
1447
|
}
|
|
1532
1448
|
};
|
|
@@ -1538,6 +1454,71 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1538
1454
|
return unmarshalValue(result, unmarshalCtx);
|
|
1539
1455
|
};
|
|
1540
1456
|
};
|
|
1457
|
+
unmarshalCtx.createPromiseProxy = (promiseId, ref) => {
|
|
1458
|
+
const resolveCallbackId = ref?.__resolveCallbackId;
|
|
1459
|
+
if (typeof resolveCallbackId !== "number") {
|
|
1460
|
+
throw new Error(`Promise ${promiseId} is missing a resolve callback`);
|
|
1461
|
+
}
|
|
1462
|
+
return (async () => {
|
|
1463
|
+
const result = await invokeDaemonCallback(state, resolveCallbackId, [promiseId]);
|
|
1464
|
+
return unmarshalValue(result, unmarshalCtx);
|
|
1465
|
+
})();
|
|
1466
|
+
};
|
|
1467
|
+
unmarshalCtx.createIteratorProxy = (iteratorId, ref) => {
|
|
1468
|
+
const nextCallbackId = ref?.__nextCallbackId;
|
|
1469
|
+
const returnCallbackId = ref?.__returnCallbackId;
|
|
1470
|
+
const throwCallbackId = ref?.__throwCallbackId;
|
|
1471
|
+
if (typeof nextCallbackId !== "number") {
|
|
1472
|
+
throw new Error(`Iterator ${iteratorId} is missing a next callback`);
|
|
1473
|
+
}
|
|
1474
|
+
const invokeIteratorCallback = async (callbackId, args, label) => {
|
|
1475
|
+
const result = await invokeDaemonCallback(state, callbackId, args);
|
|
1476
|
+
if (!result || typeof result !== "object" || !("done" in result)) {
|
|
1477
|
+
throw new Error(`${label} returned an invalid iterator result`);
|
|
1478
|
+
}
|
|
1479
|
+
return result;
|
|
1480
|
+
};
|
|
1481
|
+
return {
|
|
1482
|
+
[Symbol.asyncIterator]() {
|
|
1483
|
+
return this;
|
|
1484
|
+
},
|
|
1485
|
+
async next() {
|
|
1486
|
+
const result = await invokeIteratorCallback(nextCallbackId, [iteratorId], "Iterator next()");
|
|
1487
|
+
return {
|
|
1488
|
+
done: Boolean(result.done),
|
|
1489
|
+
value: unmarshalValue(result.value, unmarshalCtx)
|
|
1490
|
+
};
|
|
1491
|
+
},
|
|
1492
|
+
async return(value) {
|
|
1493
|
+
if (typeof returnCallbackId !== "number") {
|
|
1494
|
+
return { done: true, value };
|
|
1495
|
+
}
|
|
1496
|
+
const result = await invokeIteratorCallback(returnCallbackId, [iteratorId, value], "Iterator return()");
|
|
1497
|
+
return {
|
|
1498
|
+
done: result.done ?? true,
|
|
1499
|
+
value: unmarshalValue(result.value, unmarshalCtx)
|
|
1500
|
+
};
|
|
1501
|
+
},
|
|
1502
|
+
async throw(errorValue) {
|
|
1503
|
+
if (typeof throwCallbackId !== "number") {
|
|
1504
|
+
throw errorValue;
|
|
1505
|
+
}
|
|
1506
|
+
const serializedError = errorValue && typeof errorValue === "object" ? {
|
|
1507
|
+
message: errorValue.message,
|
|
1508
|
+
name: errorValue.name,
|
|
1509
|
+
stack: errorValue.stack
|
|
1510
|
+
} : {
|
|
1511
|
+
message: String(errorValue ?? "Iterator throw()"),
|
|
1512
|
+
name: "Error"
|
|
1513
|
+
};
|
|
1514
|
+
const result = await invokeIteratorCallback(throwCallbackId, [iteratorId, serializedError], "Iterator throw()");
|
|
1515
|
+
return {
|
|
1516
|
+
done: Boolean(result.done),
|
|
1517
|
+
value: unmarshalValue(result.value, unmarshalCtx)
|
|
1518
|
+
};
|
|
1519
|
+
}
|
|
1520
|
+
};
|
|
1521
|
+
};
|
|
1541
1522
|
for (const [name, def] of Object.entries(customFunctions)) {
|
|
1542
1523
|
if (def.type === "asyncIterator") {
|
|
1543
1524
|
const startCallbackId = state.nextCallbackId++;
|
|
@@ -1545,8 +1526,8 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1545
1526
|
try {
|
|
1546
1527
|
const fn = def.fn;
|
|
1547
1528
|
const iterator = fn(...unmarshalValue(args, unmarshalCtx));
|
|
1548
|
-
const iteratorId = nextClientIteratorId++;
|
|
1549
|
-
clientIteratorSessions.set(iteratorId, { iterator });
|
|
1529
|
+
const iteratorId = state.nextClientIteratorId++;
|
|
1530
|
+
state.clientIteratorSessions.set(iteratorId, { iterator });
|
|
1550
1531
|
return { iteratorId };
|
|
1551
1532
|
} catch (error) {
|
|
1552
1533
|
throw error;
|
|
@@ -1554,39 +1535,39 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1554
1535
|
});
|
|
1555
1536
|
const nextCallbackId = state.nextCallbackId++;
|
|
1556
1537
|
state.callbacks.set(nextCallbackId, async (iteratorId) => {
|
|
1557
|
-
const session = clientIteratorSessions.get(iteratorId);
|
|
1538
|
+
const session = state.clientIteratorSessions.get(iteratorId);
|
|
1558
1539
|
if (!session) {
|
|
1559
1540
|
throw new Error(`Iterator session ${iteratorId} not found`);
|
|
1560
1541
|
}
|
|
1561
1542
|
try {
|
|
1562
1543
|
const result = await session.iterator.next();
|
|
1563
1544
|
if (result.done) {
|
|
1564
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1545
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1565
1546
|
}
|
|
1566
1547
|
return { done: result.done, value: await marshalValue(result.value) };
|
|
1567
1548
|
} catch (error) {
|
|
1568
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1549
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1569
1550
|
throw error;
|
|
1570
1551
|
}
|
|
1571
1552
|
});
|
|
1572
1553
|
const returnCallbackId = state.nextCallbackId++;
|
|
1573
1554
|
state.callbacks.set(returnCallbackId, async (iteratorId, value) => {
|
|
1574
|
-
const session = clientIteratorSessions.get(iteratorId);
|
|
1555
|
+
const session = state.clientIteratorSessions.get(iteratorId);
|
|
1575
1556
|
if (!session) {
|
|
1576
1557
|
return { done: true, value: await marshalValue(undefined) };
|
|
1577
1558
|
}
|
|
1578
1559
|
try {
|
|
1579
1560
|
const result = await session.iterator.return?.(value);
|
|
1580
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1561
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1581
1562
|
return { done: true, value: await marshalValue(result?.value) };
|
|
1582
1563
|
} catch (error) {
|
|
1583
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1564
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1584
1565
|
throw error;
|
|
1585
1566
|
}
|
|
1586
1567
|
});
|
|
1587
1568
|
const throwCallbackId = state.nextCallbackId++;
|
|
1588
1569
|
state.callbacks.set(throwCallbackId, async (iteratorId, errorData) => {
|
|
1589
|
-
const session = clientIteratorSessions.get(iteratorId);
|
|
1570
|
+
const session = state.clientIteratorSessions.get(iteratorId);
|
|
1590
1571
|
if (!session) {
|
|
1591
1572
|
throw new Error(`Iterator session ${iteratorId} not found`);
|
|
1592
1573
|
}
|
|
@@ -1594,10 +1575,10 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1594
1575
|
const errInfo = errorData;
|
|
1595
1576
|
const error = Object.assign(new Error(errInfo.message), { name: errInfo.name });
|
|
1596
1577
|
const result = await session.iterator.throw?.(error);
|
|
1597
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1578
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1598
1579
|
return { done: result?.done ?? true, value: await marshalValue(result?.value) };
|
|
1599
1580
|
} catch (error) {
|
|
1600
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1581
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1601
1582
|
throw error;
|
|
1602
1583
|
}
|
|
1603
1584
|
});
|
|
@@ -1922,4 +1903,4 @@ export {
|
|
|
1922
1903
|
connect
|
|
1923
1904
|
};
|
|
1924
1905
|
|
|
1925
|
-
//# debugId=
|
|
1906
|
+
//# debugId=FDB88C0543F75EF564756E2164756E21
|