@ricsam/isolate 0.1.10 → 0.1.12
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 +257 -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 +230 -51
- package/dist/cjs/bridge/runtime-bindings.cjs.map +3 -3
- package/dist/cjs/bridge/sandbox-isolate.cjs +464 -0
- package/dist/cjs/bridge/sandbox-isolate.cjs.map +10 -0
- package/dist/cjs/host/create-isolate-host.cjs +130 -25
- package/dist/cjs/host/create-isolate-host.cjs.map +3 -3
- package/dist/cjs/host/nested-host-controller.cjs +369 -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 +102 -0
- package/dist/cjs/internal/browser-source.cjs.map +10 -0
- package/dist/cjs/internal/client/connection.cjs +163 -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 +156 -13
- package/dist/cjs/internal/daemon/connection.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 +2 -1
- package/dist/cjs/internal/protocol/types.cjs.map +3 -3
- 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 +218 -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/package.json +1 -1
- package/dist/cjs/playwright.cjs +76 -0
- package/dist/cjs/playwright.cjs.map +10 -0
- package/dist/cjs/runtime/namespaced-runtime.cjs +181 -0
- package/dist/cjs/runtime/namespaced-runtime.cjs.map +10 -0
- 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 +233 -51
- package/dist/mjs/bridge/runtime-bindings.mjs.map +3 -3
- package/dist/mjs/bridge/sandbox-isolate.mjs +424 -0
- package/dist/mjs/bridge/sandbox-isolate.mjs.map +10 -0
- package/dist/mjs/host/create-isolate-host.mjs +132 -25
- package/dist/mjs/host/create-isolate-host.mjs.map +3 -3
- package/dist/mjs/host/nested-host-controller.mjs +333 -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 +62 -0
- package/dist/mjs/internal/browser-source.mjs.map +10 -0
- package/dist/mjs/internal/client/connection.mjs +165 -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 +156 -13
- package/dist/mjs/internal/daemon/connection.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 +2 -1
- package/dist/mjs/internal/protocol/types.mjs.map +3 -3
- 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 +218 -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/package.json +1 -1
- package/dist/mjs/playwright.mjs +47 -0
- package/dist/mjs/playwright.mjs.map +10 -0
- package/dist/mjs/runtime/namespaced-runtime.mjs +143 -0
- package/dist/mjs/runtime/namespaced-runtime.mjs.map +10 -0
- 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 +21 -0
- package/dist/types/host/nested-host-controller.d.ts +15 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internal/browser-source.d.ts +10 -0
- package/dist/types/internal/client/types.d.ts +9 -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 +33 -2
- 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/playwright.d.ts +26 -0
- package/dist/types/runtime/namespaced-runtime.d.ts +11 -0
- 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 +75 -33
- package/package.json +8 -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
|
@@ -94,8 +94,13 @@ async function connect(options = {}) {
|
|
|
94
94
|
callbackStreamReaders: new Map,
|
|
95
95
|
activeCallbackInvocations: new Map,
|
|
96
96
|
callbackAbortControllers: new Map,
|
|
97
|
+
clientIteratorSessions: new Map,
|
|
98
|
+
returnedPromiseRegistry: new Map,
|
|
99
|
+
returnedIteratorRegistry: new Map,
|
|
97
100
|
closing: false,
|
|
98
|
-
namespacedRuntimes: new Map
|
|
101
|
+
namespacedRuntimes: new Map,
|
|
102
|
+
nextClientIteratorId: 1,
|
|
103
|
+
nextReturnedRefId: 1
|
|
99
104
|
};
|
|
100
105
|
function setupSocket(sock) {
|
|
101
106
|
const parser = import_protocol.createFrameParser();
|
|
@@ -139,6 +144,9 @@ async function connect(options = {}) {
|
|
|
139
144
|
}
|
|
140
145
|
state.callbackAbortControllers.clear();
|
|
141
146
|
state.activeCallbackInvocations.clear();
|
|
147
|
+
state.clientIteratorSessions.clear();
|
|
148
|
+
state.returnedPromiseRegistry.clear();
|
|
149
|
+
state.returnedIteratorRegistry.clear();
|
|
142
150
|
if (!state.closing && state.namespacedRuntimes.size > 0) {
|
|
143
151
|
state.reconnecting = reconnect(state, options).catch(() => {
|
|
144
152
|
state.namespacedRuntimes.clear();
|
|
@@ -247,6 +255,17 @@ async function connect(options = {}) {
|
|
|
247
255
|
id,
|
|
248
256
|
createRuntime: (runtimeOptions) => createRuntime(state, runtimeOptions, id)
|
|
249
257
|
}),
|
|
258
|
+
disposeNamespace: async (id, options2) => {
|
|
259
|
+
state.namespacedRuntimes.delete(id);
|
|
260
|
+
const requestId = state.nextRequestId++;
|
|
261
|
+
const request = {
|
|
262
|
+
type: import_protocol.MessageType.DISPOSE_NAMESPACE,
|
|
263
|
+
requestId,
|
|
264
|
+
namespaceId: id,
|
|
265
|
+
reason: typeof options2?.reason === "string" && options2.reason.length > 0 ? options2.reason : undefined
|
|
266
|
+
};
|
|
267
|
+
await sendRequest(state, request);
|
|
268
|
+
},
|
|
250
269
|
close: async () => {
|
|
251
270
|
state.closing = true;
|
|
252
271
|
state.connected = false;
|
|
@@ -659,145 +678,57 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
659
678
|
callbacks.custom = registerCustomFunctions(state, options.customFunctions);
|
|
660
679
|
}
|
|
661
680
|
let playwrightHandler;
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
681
|
+
let getCollectedData = () => ({
|
|
682
|
+
browserConsoleLogs: [],
|
|
683
|
+
pageErrors: [],
|
|
684
|
+
networkRequests: [],
|
|
685
|
+
networkResponses: [],
|
|
686
|
+
requestFailures: []
|
|
687
|
+
});
|
|
688
|
+
let getTrackedResources = () => ({
|
|
689
|
+
contexts: [],
|
|
690
|
+
pages: []
|
|
691
|
+
});
|
|
692
|
+
let clearCollectedData = () => {};
|
|
693
|
+
const playwrightListenerCleanups = [];
|
|
668
694
|
if (normalizedPlaywrightOptions) {
|
|
669
695
|
playwrightHandler = normalizedPlaywrightOptions.handler;
|
|
670
696
|
if (!playwrightHandler) {
|
|
671
697
|
throw new Error("playwright.handler is required when using playwright options");
|
|
672
698
|
}
|
|
673
|
-
const
|
|
699
|
+
const handlerMetadata = import_client.getPlaywrightHandlerMetadata(playwrightHandler);
|
|
700
|
+
if (handlerMetadata) {
|
|
701
|
+
getCollectedData = () => handlerMetadata.collector.getCollectedData();
|
|
702
|
+
getTrackedResources = () => handlerMetadata.collector.getTrackedResources();
|
|
703
|
+
clearCollectedData = () => {
|
|
704
|
+
handlerMetadata.collector.clearCollectedData();
|
|
705
|
+
};
|
|
706
|
+
playwrightListenerCleanups.push(handlerMetadata.collector.onEvent((event) => {
|
|
707
|
+
if (normalizedPlaywrightOptions.onEvent) {
|
|
708
|
+
normalizedPlaywrightOptions.onEvent(event);
|
|
709
|
+
}
|
|
710
|
+
if (event.type === "browserConsoleLog") {
|
|
711
|
+
if (normalizedPlaywrightOptions.console && options.console?.onEntry) {
|
|
712
|
+
options.console.onEntry({
|
|
713
|
+
type: "browserOutput",
|
|
714
|
+
level: event.level,
|
|
715
|
+
stdout: event.stdout,
|
|
716
|
+
location: event.location,
|
|
717
|
+
timestamp: event.timestamp
|
|
718
|
+
});
|
|
719
|
+
} else if (normalizedPlaywrightOptions.console) {
|
|
720
|
+
const prefix = event.level === "error" ? "[browser:error]" : "[browser]";
|
|
721
|
+
console.log(prefix, event.stdout);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}));
|
|
725
|
+
}
|
|
674
726
|
const handlerCallbackId = state.nextCallbackId++;
|
|
675
727
|
state.callbacks.set(handlerCallbackId, async (opJson) => {
|
|
676
728
|
const op = JSON.parse(opJson);
|
|
677
729
|
const result2 = await playwrightHandler(op);
|
|
678
730
|
return JSON.stringify(result2);
|
|
679
731
|
});
|
|
680
|
-
if (page) {
|
|
681
|
-
const requestIds = new WeakMap;
|
|
682
|
-
let nextRequestId = 1;
|
|
683
|
-
const getRequestId = (request2) => {
|
|
684
|
-
let requestId2 = requestIds.get(request2);
|
|
685
|
-
if (!requestId2) {
|
|
686
|
-
requestId2 = `req_${nextRequestId++}`;
|
|
687
|
-
requestIds.set(request2, requestId2);
|
|
688
|
-
}
|
|
689
|
-
return requestId2;
|
|
690
|
-
};
|
|
691
|
-
const toLocation = (location) => {
|
|
692
|
-
if (!location || !location.url && location.lineNumber == null && location.columnNumber == null) {
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
return {
|
|
696
|
-
url: location.url || undefined,
|
|
697
|
-
lineNumber: location.lineNumber != null ? location.lineNumber + 1 : undefined,
|
|
698
|
-
columnNumber: location.columnNumber != null ? location.columnNumber + 1 : undefined
|
|
699
|
-
};
|
|
700
|
-
};
|
|
701
|
-
const onConsole = (msg) => {
|
|
702
|
-
const entry = {
|
|
703
|
-
level: msg.type(),
|
|
704
|
-
stdout: msg.text(),
|
|
705
|
-
location: toLocation(msg.location()),
|
|
706
|
-
timestamp: Date.now()
|
|
707
|
-
};
|
|
708
|
-
browserConsoleLogs.push(entry);
|
|
709
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
710
|
-
normalizedPlaywrightOptions.onEvent({
|
|
711
|
-
type: "browserConsoleLog",
|
|
712
|
-
...entry
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
if (normalizedPlaywrightOptions.console && options.console?.onEntry) {
|
|
716
|
-
options.console.onEntry({
|
|
717
|
-
type: "browserOutput",
|
|
718
|
-
...entry
|
|
719
|
-
});
|
|
720
|
-
} else if (normalizedPlaywrightOptions.console) {
|
|
721
|
-
const prefix = entry.level === "error" ? "[browser:error]" : "[browser]";
|
|
722
|
-
console.log(prefix, entry.stdout);
|
|
723
|
-
}
|
|
724
|
-
};
|
|
725
|
-
const onRequest = (request2) => {
|
|
726
|
-
const info = {
|
|
727
|
-
requestId: getRequestId(request2),
|
|
728
|
-
url: request2.url(),
|
|
729
|
-
method: request2.method(),
|
|
730
|
-
headers: request2.headers(),
|
|
731
|
-
postData: request2.postData() ?? undefined,
|
|
732
|
-
resourceType: request2.resourceType(),
|
|
733
|
-
timestamp: Date.now()
|
|
734
|
-
};
|
|
735
|
-
networkRequests.push(info);
|
|
736
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
737
|
-
normalizedPlaywrightOptions.onEvent({
|
|
738
|
-
type: "networkRequest",
|
|
739
|
-
...info
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
const onResponse = (response) => {
|
|
744
|
-
const request2 = response.request();
|
|
745
|
-
const info = {
|
|
746
|
-
requestId: getRequestId(request2),
|
|
747
|
-
url: response.url(),
|
|
748
|
-
status: response.status(),
|
|
749
|
-
statusText: response.statusText(),
|
|
750
|
-
headers: response.headers(),
|
|
751
|
-
resourceType: request2.resourceType(),
|
|
752
|
-
timestamp: Date.now()
|
|
753
|
-
};
|
|
754
|
-
networkResponses.push(info);
|
|
755
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
756
|
-
normalizedPlaywrightOptions.onEvent({
|
|
757
|
-
type: "networkResponse",
|
|
758
|
-
...info
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
};
|
|
762
|
-
const onRequestFailed = (request2) => {
|
|
763
|
-
const info = {
|
|
764
|
-
requestId: getRequestId(request2),
|
|
765
|
-
url: request2.url(),
|
|
766
|
-
method: request2.method(),
|
|
767
|
-
failureText: request2.failure()?.errorText || "request failed",
|
|
768
|
-
resourceType: request2.resourceType(),
|
|
769
|
-
timestamp: Date.now()
|
|
770
|
-
};
|
|
771
|
-
requestFailures.push(info);
|
|
772
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
773
|
-
normalizedPlaywrightOptions.onEvent({
|
|
774
|
-
type: "requestFailure",
|
|
775
|
-
...info
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
const onPageError = (error) => {
|
|
780
|
-
const entry = {
|
|
781
|
-
name: error.name,
|
|
782
|
-
message: error.message,
|
|
783
|
-
stack: error.stack,
|
|
784
|
-
timestamp: Date.now()
|
|
785
|
-
};
|
|
786
|
-
pageErrors.push(entry);
|
|
787
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
788
|
-
normalizedPlaywrightOptions.onEvent({
|
|
789
|
-
type: "pageError",
|
|
790
|
-
...entry
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
};
|
|
794
|
-
page.on("console", onConsole);
|
|
795
|
-
page.on("request", onRequest);
|
|
796
|
-
page.on("response", onResponse);
|
|
797
|
-
page.on("requestfailed", onRequestFailed);
|
|
798
|
-
page.on("pageerror", onPageError);
|
|
799
|
-
pageListenerCleanups.push(() => page.removeListener("console", onConsole), () => page.removeListener("request", onRequest), () => page.removeListener("response", onResponse), () => page.removeListener("requestfailed", onRequestFailed), () => page.removeListener("pageerror", onPageError));
|
|
800
|
-
}
|
|
801
732
|
callbacks.playwright = {
|
|
802
733
|
handlerCallbackId,
|
|
803
734
|
console: normalizedPlaywrightOptions.console && !options.console?.onEntry
|
|
@@ -828,7 +759,10 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
828
759
|
testEnvironmentOption = true;
|
|
829
760
|
}
|
|
830
761
|
}
|
|
831
|
-
const playwrightOption = normalizedPlaywrightOptions
|
|
762
|
+
const playwrightOption = normalizedPlaywrightOptions ? {
|
|
763
|
+
timeout: normalizedPlaywrightOptions.timeout,
|
|
764
|
+
hasDefaultPage: normalizedPlaywrightOptions.hasDefaultPage
|
|
765
|
+
} : undefined;
|
|
832
766
|
const requestId = state.nextRequestId++;
|
|
833
767
|
const request = {
|
|
834
768
|
type: import_protocol.MessageType.CREATE_RUNTIME,
|
|
@@ -1139,23 +1073,19 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
1139
1073
|
if (!playwrightEnabled) {
|
|
1140
1074
|
throw new Error("Playwright not configured. Provide playwright.handler in createRuntime options.");
|
|
1141
1075
|
}
|
|
1142
|
-
return
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1076
|
+
return getCollectedData();
|
|
1077
|
+
},
|
|
1078
|
+
getTrackedResources() {
|
|
1079
|
+
if (!playwrightEnabled) {
|
|
1080
|
+
throw new Error("Playwright not configured. Provide playwright.handler in createRuntime options.");
|
|
1081
|
+
}
|
|
1082
|
+
return getTrackedResources();
|
|
1149
1083
|
},
|
|
1150
1084
|
clearCollectedData() {
|
|
1151
1085
|
if (!playwrightEnabled) {
|
|
1152
1086
|
throw new Error("Playwright not configured. Provide playwright.handler in createRuntime options.");
|
|
1153
1087
|
}
|
|
1154
|
-
|
|
1155
|
-
pageErrors.length = 0;
|
|
1156
|
-
networkRequests.length = 0;
|
|
1157
|
-
networkResponses.length = 0;
|
|
1158
|
-
requestFailures.length = 0;
|
|
1088
|
+
clearCollectedData();
|
|
1159
1089
|
}
|
|
1160
1090
|
};
|
|
1161
1091
|
return {
|
|
@@ -1210,7 +1140,7 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
1210
1140
|
});
|
|
1211
1141
|
},
|
|
1212
1142
|
dispose: async (options2) => {
|
|
1213
|
-
for (const cleanup of
|
|
1143
|
+
for (const cleanup of playwrightListenerCleanups) {
|
|
1214
1144
|
cleanup();
|
|
1215
1145
|
}
|
|
1216
1146
|
isolateWsCallbacks.delete(isolateId);
|
|
@@ -1454,10 +1384,6 @@ function registerModuleLoaderCallback(state, callback) {
|
|
|
1454
1384
|
});
|
|
1455
1385
|
return { callbackId, name: "moduleLoader", type: "async" };
|
|
1456
1386
|
}
|
|
1457
|
-
var clientIteratorSessions = new Map;
|
|
1458
|
-
var nextClientIteratorId = 1;
|
|
1459
|
-
var returnedPromiseRegistry = new Map;
|
|
1460
|
-
var returnedIteratorRegistry = new Map;
|
|
1461
1387
|
function registerCustomFunctions(state, customFunctions) {
|
|
1462
1388
|
const registrations = {};
|
|
1463
1389
|
const addCallbackIdsToRefs = (value) => {
|
|
@@ -1468,12 +1394,12 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1468
1394
|
const resolveCallbackId = state.nextCallbackId++;
|
|
1469
1395
|
state.callbacks.set(resolveCallbackId, async (...args) => {
|
|
1470
1396
|
const promiseId = args[0];
|
|
1471
|
-
const promise = returnedPromiseRegistry.get(promiseId);
|
|
1397
|
+
const promise = state.returnedPromiseRegistry.get(promiseId);
|
|
1472
1398
|
if (!promise) {
|
|
1473
1399
|
throw new Error(`Promise ${promiseId} not found`);
|
|
1474
1400
|
}
|
|
1475
1401
|
const promiseResult = await promise;
|
|
1476
|
-
returnedPromiseRegistry.delete(promiseId);
|
|
1402
|
+
state.returnedPromiseRegistry.delete(promiseId);
|
|
1477
1403
|
const marshalledResult = await import_protocol.marshalValue(promiseResult, marshalCtx);
|
|
1478
1404
|
return addCallbackIdsToRefs(marshalledResult);
|
|
1479
1405
|
});
|
|
@@ -1486,13 +1412,13 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1486
1412
|
const nextCallbackId = state.nextCallbackId++;
|
|
1487
1413
|
state.callbacks.set(nextCallbackId, async (...args) => {
|
|
1488
1414
|
const iteratorId = args[0];
|
|
1489
|
-
const iterator = returnedIteratorRegistry.get(iteratorId);
|
|
1415
|
+
const iterator = state.returnedIteratorRegistry.get(iteratorId);
|
|
1490
1416
|
if (!iterator) {
|
|
1491
1417
|
throw new Error(`Iterator ${iteratorId} not found`);
|
|
1492
1418
|
}
|
|
1493
1419
|
const iterResult = await iterator.next();
|
|
1494
1420
|
if (iterResult.done) {
|
|
1495
|
-
returnedIteratorRegistry.delete(iteratorId);
|
|
1421
|
+
state.returnedIteratorRegistry.delete(iteratorId);
|
|
1496
1422
|
}
|
|
1497
1423
|
const marshalledValue = await import_protocol.marshalValue(iterResult.value, marshalCtx);
|
|
1498
1424
|
return {
|
|
@@ -1504,8 +1430,8 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1504
1430
|
state.callbacks.set(returnCallbackId, async (...args) => {
|
|
1505
1431
|
const iteratorId = args[0];
|
|
1506
1432
|
const returnValue = args[1];
|
|
1507
|
-
const iterator = returnedIteratorRegistry.get(iteratorId);
|
|
1508
|
-
returnedIteratorRegistry.delete(iteratorId);
|
|
1433
|
+
const iterator = state.returnedIteratorRegistry.get(iteratorId);
|
|
1434
|
+
state.returnedIteratorRegistry.delete(iteratorId);
|
|
1509
1435
|
if (!iterator || !iterator.return) {
|
|
1510
1436
|
return { done: true, value: undefined };
|
|
1511
1437
|
}
|
|
@@ -1520,7 +1446,7 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1520
1446
|
state.callbacks.set(throwCallbackId, async (...args) => {
|
|
1521
1447
|
const iteratorId = args[0];
|
|
1522
1448
|
const errorValue = args[1];
|
|
1523
|
-
const iterator = returnedIteratorRegistry.get(iteratorId);
|
|
1449
|
+
const iterator = state.returnedIteratorRegistry.get(iteratorId);
|
|
1524
1450
|
if (!iterator) {
|
|
1525
1451
|
throw new Error(`Iterator ${iteratorId} not found`);
|
|
1526
1452
|
}
|
|
@@ -1531,7 +1457,7 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1531
1457
|
const thrownError = Object.assign(new Error(errorValue?.message ?? "Iterator throw()"), { name: errorValue?.name ?? "Error", stack: errorValue?.stack });
|
|
1532
1458
|
const iterResult = await iterator.throw(thrownError);
|
|
1533
1459
|
if (iterResult.done) {
|
|
1534
|
-
returnedIteratorRegistry.delete(iteratorId);
|
|
1460
|
+
state.returnedIteratorRegistry.delete(iteratorId);
|
|
1535
1461
|
}
|
|
1536
1462
|
const marshalledValue = await import_protocol.marshalValue(iterResult.value, marshalCtx);
|
|
1537
1463
|
return {
|
|
@@ -1539,7 +1465,7 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1539
1465
|
value: addCallbackIdsToRefs(marshalledValue)
|
|
1540
1466
|
};
|
|
1541
1467
|
} catch (error) {
|
|
1542
|
-
returnedIteratorRegistry.delete(iteratorId);
|
|
1468
|
+
state.returnedIteratorRegistry.delete(iteratorId);
|
|
1543
1469
|
throw error;
|
|
1544
1470
|
}
|
|
1545
1471
|
});
|
|
@@ -1570,13 +1496,13 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1570
1496
|
return returnedCallbackId;
|
|
1571
1497
|
},
|
|
1572
1498
|
registerPromise: (promise) => {
|
|
1573
|
-
const promiseId = state.
|
|
1574
|
-
returnedPromiseRegistry.set(promiseId, promise);
|
|
1499
|
+
const promiseId = state.nextReturnedRefId++;
|
|
1500
|
+
state.returnedPromiseRegistry.set(promiseId, promise);
|
|
1575
1501
|
return promiseId;
|
|
1576
1502
|
},
|
|
1577
1503
|
registerIterator: (iterator) => {
|
|
1578
|
-
const iteratorId = state.
|
|
1579
|
-
returnedIteratorRegistry.set(iteratorId, iterator);
|
|
1504
|
+
const iteratorId = state.nextReturnedRefId++;
|
|
1505
|
+
state.returnedIteratorRegistry.set(iteratorId, iterator);
|
|
1580
1506
|
return iteratorId;
|
|
1581
1507
|
}
|
|
1582
1508
|
};
|
|
@@ -1588,6 +1514,71 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1588
1514
|
return import_protocol.unmarshalValue(result, unmarshalCtx);
|
|
1589
1515
|
};
|
|
1590
1516
|
};
|
|
1517
|
+
unmarshalCtx.createPromiseProxy = (promiseId, ref) => {
|
|
1518
|
+
const resolveCallbackId = ref?.__resolveCallbackId;
|
|
1519
|
+
if (typeof resolveCallbackId !== "number") {
|
|
1520
|
+
throw new Error(`Promise ${promiseId} is missing a resolve callback`);
|
|
1521
|
+
}
|
|
1522
|
+
return (async () => {
|
|
1523
|
+
const result = await invokeDaemonCallback(state, resolveCallbackId, [promiseId]);
|
|
1524
|
+
return import_protocol.unmarshalValue(result, unmarshalCtx);
|
|
1525
|
+
})();
|
|
1526
|
+
};
|
|
1527
|
+
unmarshalCtx.createIteratorProxy = (iteratorId, ref) => {
|
|
1528
|
+
const nextCallbackId = ref?.__nextCallbackId;
|
|
1529
|
+
const returnCallbackId = ref?.__returnCallbackId;
|
|
1530
|
+
const throwCallbackId = ref?.__throwCallbackId;
|
|
1531
|
+
if (typeof nextCallbackId !== "number") {
|
|
1532
|
+
throw new Error(`Iterator ${iteratorId} is missing a next callback`);
|
|
1533
|
+
}
|
|
1534
|
+
const invokeIteratorCallback = async (callbackId, args, label) => {
|
|
1535
|
+
const result = await invokeDaemonCallback(state, callbackId, args);
|
|
1536
|
+
if (!result || typeof result !== "object" || !("done" in result)) {
|
|
1537
|
+
throw new Error(`${label} returned an invalid iterator result`);
|
|
1538
|
+
}
|
|
1539
|
+
return result;
|
|
1540
|
+
};
|
|
1541
|
+
return {
|
|
1542
|
+
[Symbol.asyncIterator]() {
|
|
1543
|
+
return this;
|
|
1544
|
+
},
|
|
1545
|
+
async next() {
|
|
1546
|
+
const result = await invokeIteratorCallback(nextCallbackId, [iteratorId], "Iterator next()");
|
|
1547
|
+
return {
|
|
1548
|
+
done: Boolean(result.done),
|
|
1549
|
+
value: import_protocol.unmarshalValue(result.value, unmarshalCtx)
|
|
1550
|
+
};
|
|
1551
|
+
},
|
|
1552
|
+
async return(value) {
|
|
1553
|
+
if (typeof returnCallbackId !== "number") {
|
|
1554
|
+
return { done: true, value };
|
|
1555
|
+
}
|
|
1556
|
+
const result = await invokeIteratorCallback(returnCallbackId, [iteratorId, value], "Iterator return()");
|
|
1557
|
+
return {
|
|
1558
|
+
done: result.done ?? true,
|
|
1559
|
+
value: import_protocol.unmarshalValue(result.value, unmarshalCtx)
|
|
1560
|
+
};
|
|
1561
|
+
},
|
|
1562
|
+
async throw(errorValue) {
|
|
1563
|
+
if (typeof throwCallbackId !== "number") {
|
|
1564
|
+
throw errorValue;
|
|
1565
|
+
}
|
|
1566
|
+
const serializedError = errorValue && typeof errorValue === "object" ? {
|
|
1567
|
+
message: errorValue.message,
|
|
1568
|
+
name: errorValue.name,
|
|
1569
|
+
stack: errorValue.stack
|
|
1570
|
+
} : {
|
|
1571
|
+
message: String(errorValue ?? "Iterator throw()"),
|
|
1572
|
+
name: "Error"
|
|
1573
|
+
};
|
|
1574
|
+
const result = await invokeIteratorCallback(throwCallbackId, [iteratorId, serializedError], "Iterator throw()");
|
|
1575
|
+
return {
|
|
1576
|
+
done: Boolean(result.done),
|
|
1577
|
+
value: import_protocol.unmarshalValue(result.value, unmarshalCtx)
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1581
|
+
};
|
|
1591
1582
|
for (const [name, def] of Object.entries(customFunctions)) {
|
|
1592
1583
|
if (def.type === "asyncIterator") {
|
|
1593
1584
|
const startCallbackId = state.nextCallbackId++;
|
|
@@ -1595,8 +1586,8 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1595
1586
|
try {
|
|
1596
1587
|
const fn = def.fn;
|
|
1597
1588
|
const iterator = fn(...import_protocol.unmarshalValue(args, unmarshalCtx));
|
|
1598
|
-
const iteratorId = nextClientIteratorId++;
|
|
1599
|
-
clientIteratorSessions.set(iteratorId, { iterator });
|
|
1589
|
+
const iteratorId = state.nextClientIteratorId++;
|
|
1590
|
+
state.clientIteratorSessions.set(iteratorId, { iterator });
|
|
1600
1591
|
return { iteratorId };
|
|
1601
1592
|
} catch (error) {
|
|
1602
1593
|
throw error;
|
|
@@ -1604,39 +1595,39 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1604
1595
|
});
|
|
1605
1596
|
const nextCallbackId = state.nextCallbackId++;
|
|
1606
1597
|
state.callbacks.set(nextCallbackId, async (iteratorId) => {
|
|
1607
|
-
const session = clientIteratorSessions.get(iteratorId);
|
|
1598
|
+
const session = state.clientIteratorSessions.get(iteratorId);
|
|
1608
1599
|
if (!session) {
|
|
1609
1600
|
throw new Error(`Iterator session ${iteratorId} not found`);
|
|
1610
1601
|
}
|
|
1611
1602
|
try {
|
|
1612
1603
|
const result = await session.iterator.next();
|
|
1613
1604
|
if (result.done) {
|
|
1614
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1605
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1615
1606
|
}
|
|
1616
1607
|
return { done: result.done, value: await import_protocol.marshalValue(result.value) };
|
|
1617
1608
|
} catch (error) {
|
|
1618
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1609
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1619
1610
|
throw error;
|
|
1620
1611
|
}
|
|
1621
1612
|
});
|
|
1622
1613
|
const returnCallbackId = state.nextCallbackId++;
|
|
1623
1614
|
state.callbacks.set(returnCallbackId, async (iteratorId, value) => {
|
|
1624
|
-
const session = clientIteratorSessions.get(iteratorId);
|
|
1615
|
+
const session = state.clientIteratorSessions.get(iteratorId);
|
|
1625
1616
|
if (!session) {
|
|
1626
1617
|
return { done: true, value: await import_protocol.marshalValue(undefined) };
|
|
1627
1618
|
}
|
|
1628
1619
|
try {
|
|
1629
1620
|
const result = await session.iterator.return?.(value);
|
|
1630
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1621
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1631
1622
|
return { done: true, value: await import_protocol.marshalValue(result?.value) };
|
|
1632
1623
|
} catch (error) {
|
|
1633
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1624
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1634
1625
|
throw error;
|
|
1635
1626
|
}
|
|
1636
1627
|
});
|
|
1637
1628
|
const throwCallbackId = state.nextCallbackId++;
|
|
1638
1629
|
state.callbacks.set(throwCallbackId, async (iteratorId, errorData) => {
|
|
1639
|
-
const session = clientIteratorSessions.get(iteratorId);
|
|
1630
|
+
const session = state.clientIteratorSessions.get(iteratorId);
|
|
1640
1631
|
if (!session) {
|
|
1641
1632
|
throw new Error(`Iterator session ${iteratorId} not found`);
|
|
1642
1633
|
}
|
|
@@ -1644,10 +1635,10 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1644
1635
|
const errInfo = errorData;
|
|
1645
1636
|
const error = Object.assign(new Error(errInfo.message), { name: errInfo.name });
|
|
1646
1637
|
const result = await session.iterator.throw?.(error);
|
|
1647
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1638
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1648
1639
|
return { done: result?.done ?? true, value: await import_protocol.marshalValue(result?.value) };
|
|
1649
1640
|
} catch (error) {
|
|
1650
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1641
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1651
1642
|
throw error;
|
|
1652
1643
|
}
|
|
1653
1644
|
});
|
|
@@ -1968,4 +1959,4 @@ function handleClientWsClose(isolateId, payload, state) {
|
|
|
1968
1959
|
}
|
|
1969
1960
|
}
|
|
1970
1961
|
|
|
1971
|
-
//# debugId=
|
|
1962
|
+
//# debugId=6DFCE44C7F91C20864756E2164756E21
|