@ricsam/isolate-client 0.1.20 → 0.1.21

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.
@@ -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 (options.playwright) {
549
- playwrightHandler = options.playwright.handler;
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 (options.playwright.onEvent) {
569
- options.playwright.onEvent({
595
+ if (normalizedPlaywrightOptions.onEvent) {
596
+ normalizedPlaywrightOptions.onEvent({
570
597
  type: "browserConsoleLog",
571
598
  ...entry
572
599
  });
573
600
  }
574
- if (options.playwright.console && options.console?.onEntry) {
601
+ if (normalizedPlaywrightOptions.console && options.console?.onEntry) {
575
602
  options.console.onEntry({
576
603
  type: "browserOutput",
577
604
  ...entry
578
605
  });
579
- } else if (options.playwright.console) {
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 (options.playwright.onEvent) {
593
- options.playwright.onEvent({
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 (options.playwright.onEvent) {
608
- options.playwright.onEvent({
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: options.playwright.console && !options.console?.onEntry
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: options
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 = !!options.playwright;
909
+ const playwrightEnabled = !!normalizedPlaywrightOptions;
881
910
  const testEnvironmentHandle = {
882
911
  async runTests(timeout) {
883
912
  if (!testEnvironmentEnabled) {
@@ -1712,4 +1741,4 @@ function handleClientWsClose(isolateId, payload, state) {
1712
1741
  }
1713
1742
  }
1714
1743
 
1715
- //# debugId=C08D5EB489DD9C9D64756E2164756E21
1744
+ //# debugId=075DBBC817BADA7264756E2164756E21