@ricsam/isolate-client 0.1.20 → 0.1.22
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/cjs/connection.cjs
CHANGED
|
@@ -204,6 +204,7 @@ async function connect(options = {}) {
|
|
|
204
204
|
testEnvironmentOption = true;
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
|
+
const playwrightOption = runtimeOptions.playwright?.timeout !== undefined ? { timeout: runtimeOptions.playwright.timeout } : undefined;
|
|
207
208
|
const requestId = st.nextRequestId++;
|
|
208
209
|
const request = {
|
|
209
210
|
type: import_isolate_protocol.MessageType.CREATE_RUNTIME,
|
|
@@ -213,6 +214,7 @@ async function connect(options = {}) {
|
|
|
213
214
|
cwd: runtimeOptions.cwd,
|
|
214
215
|
callbacks,
|
|
215
216
|
testEnvironment: testEnvironmentOption,
|
|
217
|
+
playwright: playwrightOption,
|
|
216
218
|
namespaceId
|
|
217
219
|
}
|
|
218
220
|
};
|
|
@@ -523,7 +525,32 @@ function isBenignDisposeError(error) {
|
|
|
523
525
|
const message = error instanceof Error ? error.message : String(error ?? "");
|
|
524
526
|
return /isolate not owned by this connection|isolate not found|not connected|connection closed/i.test(message);
|
|
525
527
|
}
|
|
528
|
+
function normalizePlaywrightOptions(playwrightOptions) {
|
|
529
|
+
if (!playwrightOptions || playwrightOptions.timeout === undefined) {
|
|
530
|
+
return playwrightOptions;
|
|
531
|
+
}
|
|
532
|
+
const metadata = import_client.getDefaultPlaywrightHandlerMetadata(playwrightOptions.handler);
|
|
533
|
+
if (!metadata?.page) {
|
|
534
|
+
return playwrightOptions;
|
|
535
|
+
}
|
|
536
|
+
const currentTimeout = metadata.options?.timeout ?? 30000;
|
|
537
|
+
if (currentTimeout === playwrightOptions.timeout) {
|
|
538
|
+
return playwrightOptions;
|
|
539
|
+
}
|
|
540
|
+
return {
|
|
541
|
+
...playwrightOptions,
|
|
542
|
+
handler: import_client.defaultPlaywrightHandler(metadata.page, {
|
|
543
|
+
...metadata.options,
|
|
544
|
+
timeout: playwrightOptions.timeout
|
|
545
|
+
})
|
|
546
|
+
};
|
|
547
|
+
}
|
|
526
548
|
async function createRuntime(state, options = {}, namespaceId) {
|
|
549
|
+
const normalizedPlaywrightOptions = normalizePlaywrightOptions(options.playwright);
|
|
550
|
+
const runtimeOptionsForReconnect = normalizedPlaywrightOptions === options.playwright ? options : {
|
|
551
|
+
...options,
|
|
552
|
+
playwright: normalizedPlaywrightOptions
|
|
553
|
+
};
|
|
527
554
|
const callbacks = {};
|
|
528
555
|
if (options.console) {
|
|
529
556
|
callbacks.console = registerConsoleCallbacks(state, options.console);
|
|
@@ -545,8 +572,8 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
545
572
|
const networkRequests = [];
|
|
546
573
|
const networkResponses = [];
|
|
547
574
|
const pageListenerCleanups = [];
|
|
548
|
-
if (
|
|
549
|
-
playwrightHandler =
|
|
575
|
+
if (normalizedPlaywrightOptions) {
|
|
576
|
+
playwrightHandler = normalizedPlaywrightOptions.handler;
|
|
550
577
|
if (!playwrightHandler) {
|
|
551
578
|
throw new Error("playwright.handler is required when using playwright options");
|
|
552
579
|
}
|
|
@@ -565,18 +592,18 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
565
592
|
timestamp: Date.now()
|
|
566
593
|
};
|
|
567
594
|
browserConsoleLogs.push(entry);
|
|
568
|
-
if (
|
|
569
|
-
|
|
595
|
+
if (normalizedPlaywrightOptions.onEvent) {
|
|
596
|
+
normalizedPlaywrightOptions.onEvent({
|
|
570
597
|
type: "browserConsoleLog",
|
|
571
598
|
...entry
|
|
572
599
|
});
|
|
573
600
|
}
|
|
574
|
-
if (
|
|
601
|
+
if (normalizedPlaywrightOptions.console && options.console?.onEntry) {
|
|
575
602
|
options.console.onEntry({
|
|
576
603
|
type: "browserOutput",
|
|
577
604
|
...entry
|
|
578
605
|
});
|
|
579
|
-
} else if (
|
|
606
|
+
} else if (normalizedPlaywrightOptions.console) {
|
|
580
607
|
const prefix = entry.level === "error" ? "[browser:error]" : "[browser]";
|
|
581
608
|
console.log(prefix, entry.stdout);
|
|
582
609
|
}
|
|
@@ -589,8 +616,8 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
589
616
|
timestamp: Date.now()
|
|
590
617
|
};
|
|
591
618
|
networkRequests.push(info);
|
|
592
|
-
if (
|
|
593
|
-
|
|
619
|
+
if (normalizedPlaywrightOptions.onEvent) {
|
|
620
|
+
normalizedPlaywrightOptions.onEvent({
|
|
594
621
|
type: "networkRequest",
|
|
595
622
|
...info
|
|
596
623
|
});
|
|
@@ -604,8 +631,8 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
604
631
|
timestamp: Date.now()
|
|
605
632
|
};
|
|
606
633
|
networkResponses.push(info);
|
|
607
|
-
if (
|
|
608
|
-
|
|
634
|
+
if (normalizedPlaywrightOptions.onEvent) {
|
|
635
|
+
normalizedPlaywrightOptions.onEvent({
|
|
609
636
|
type: "networkResponse",
|
|
610
637
|
...info
|
|
611
638
|
});
|
|
@@ -618,7 +645,7 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
618
645
|
}
|
|
619
646
|
callbacks.playwright = {
|
|
620
647
|
handlerCallbackId,
|
|
621
|
-
console:
|
|
648
|
+
console: normalizedPlaywrightOptions.console && !options.console?.onEntry
|
|
622
649
|
};
|
|
623
650
|
}
|
|
624
651
|
let testEnvironmentOption;
|
|
@@ -646,6 +673,7 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
646
673
|
testEnvironmentOption = true;
|
|
647
674
|
}
|
|
648
675
|
}
|
|
676
|
+
const playwrightOption = normalizedPlaywrightOptions?.timeout !== undefined ? { timeout: normalizedPlaywrightOptions.timeout } : undefined;
|
|
649
677
|
const requestId = state.nextRequestId++;
|
|
650
678
|
const request = {
|
|
651
679
|
type: import_isolate_protocol.MessageType.CREATE_RUNTIME,
|
|
@@ -655,6 +683,7 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
655
683
|
cwd: options.cwd,
|
|
656
684
|
callbacks,
|
|
657
685
|
testEnvironment: testEnvironmentOption,
|
|
686
|
+
playwright: playwrightOption,
|
|
658
687
|
namespaceId
|
|
659
688
|
}
|
|
660
689
|
};
|
|
@@ -664,7 +693,7 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
664
693
|
if (namespaceId != null) {
|
|
665
694
|
state.namespacedRuntimes.set(namespaceId, {
|
|
666
695
|
isolateId,
|
|
667
|
-
runtimeOptions:
|
|
696
|
+
runtimeOptions: runtimeOptionsForReconnect
|
|
668
697
|
});
|
|
669
698
|
}
|
|
670
699
|
const wsCommandCallbacks = new Set;
|
|
@@ -877,7 +906,7 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
877
906
|
}
|
|
878
907
|
};
|
|
879
908
|
const testEnvironmentEnabled = !!options.testEnvironment;
|
|
880
|
-
const playwrightEnabled = !!
|
|
909
|
+
const playwrightEnabled = !!normalizedPlaywrightOptions;
|
|
881
910
|
const testEnvironmentHandle = {
|
|
882
911
|
async runTests(timeout) {
|
|
883
912
|
if (!testEnvironmentEnabled) {
|
|
@@ -1069,6 +1098,7 @@ function registerConsoleCallbacks(state, callbacks) {
|
|
|
1069
1098
|
return registrations;
|
|
1070
1099
|
}
|
|
1071
1100
|
var CALLBACK_STREAM_THRESHOLD = 64 * 1024;
|
|
1101
|
+
var NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);
|
|
1072
1102
|
function registerFetchCallback(state, callback) {
|
|
1073
1103
|
const callbackId = state.nextCallbackId++;
|
|
1074
1104
|
state.callbacksNeedingRequestId.add(callbackId);
|
|
@@ -1089,7 +1119,7 @@ function registerFetchCallback(state, callback) {
|
|
|
1089
1119
|
const contentLength = response.headers.get("content-length");
|
|
1090
1120
|
const knownSize = contentLength ? parseInt(contentLength, 10) : null;
|
|
1091
1121
|
const isNetworkResponse = response.url && (response.url.startsWith("http://") || response.url.startsWith("https://"));
|
|
1092
|
-
const shouldStream = isNetworkResponse && response.body && (knownSize === null || knownSize > CALLBACK_STREAM_THRESHOLD);
|
|
1122
|
+
const shouldStream = isNetworkResponse && !NULL_BODY_STATUSES.has(response.status) && !!response.body && (knownSize === null || knownSize > CALLBACK_STREAM_THRESHOLD);
|
|
1093
1123
|
if (shouldStream && response.body) {
|
|
1094
1124
|
const streamId = state.nextStreamId++;
|
|
1095
1125
|
const headers = [];
|
|
@@ -1712,4 +1742,4 @@ function handleClientWsClose(isolateId, payload, state) {
|
|
|
1712
1742
|
}
|
|
1713
1743
|
}
|
|
1714
1744
|
|
|
1715
|
-
//# debugId=
|
|
1745
|
+
//# debugId=9D2040E2D4C3FD6F64756E2164756E21
|