@midscene/cli 1.12.9 → 1.12.10-beta-20260918062325.0

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.
@@ -2639,6 +2639,7 @@ function printExecutionPlan(config) {
2639
2639
  console.log(` Continue on error: ${config.continueOnError}`);
2640
2640
  console.log(` Retry: ${config.retry ?? 0}`);
2641
2641
  console.log(` Share browser context: ${config.shareBrowserContext ?? false}`);
2642
+ console.log(` Reuse browser page: ${config.reusePage ?? false}`);
2642
2643
  console.log(` Summary output: ${config.summary}`);
2643
2644
  }
2644
2645
  function printExecutionFinished() {
@@ -3603,11 +3604,22 @@ const assertBrowserContextUsage = (setupContext, allContexts, shareBrowserContex
3603
3604
  }
3604
3605
  if (setupContext && !shareBrowserContext && 'puppeteer-web' === resolveBatchRuntimeTarget(setupContext.executionConfig)) throw new Error(`Puppeteer Web setup "${setupContext.file}" requires shareBrowserContext: true so its browser state can be shared with the main files.`);
3605
3606
  };
3606
- const createSharedBrowserRuntime = async (browser, browserContextOptions)=>{
3607
+ const createSharedBrowserRuntime = async (browser, browserContextOptions, reusePage = false)=>{
3607
3608
  const browserContext = await browser.createBrowserContext(browserContextOptions);
3608
- return {
3609
- browserContext
3610
- };
3609
+ try {
3610
+ const page = reusePage ? await browserContext.newPage() : void 0;
3611
+ return {
3612
+ browserContext,
3613
+ page
3614
+ };
3615
+ } catch (error) {
3616
+ try {
3617
+ await browserContext.close();
3618
+ } catch (cleanupError) {
3619
+ batchWarning('failed to close the shared browser context after page creation failed; preserving the original error', cleanupError);
3620
+ }
3621
+ throw error;
3622
+ }
3611
3623
  };
3612
3624
  class YamlBatchExecutor {
3613
3625
  async run(options = {}) {
@@ -3692,10 +3704,11 @@ class YamlBatchExecutor {
3692
3704
  sharedRuntime.current = null;
3693
3705
  await staleRuntime.browserContext.close();
3694
3706
  }
3695
- sharedRuntime.current = await createSharedBrowserRuntime(browser, browserContextOptions);
3707
+ sharedRuntime.current = await createSharedBrowserRuntime(browser, browserContextOptions, this.config.reusePage);
3696
3708
  for (const context of allContexts){
3697
3709
  context.options.browser = browser;
3698
3710
  context.options.browserContext = sharedRuntime.current.browserContext;
3711
+ if (sharedRuntime.current.page) context.options.page = sharedRuntime.current.page;
3699
3712
  }
3700
3713
  };
3701
3714
  await resetSetupRuntime();
@@ -3975,6 +3988,8 @@ class YamlBatchExecutor {
3975
3988
  }, (_, index)=>`batch-occurrence-${index + 1}`);
3976
3989
  if (this.caseIds.length !== occurrenceCount) throw new Error(`Batch occurrence identity mismatch: expected ${occurrenceCount} case ID(s), received ${this.caseIds.length}`);
3977
3990
  if (new Set(this.caseIds).size !== this.caseIds.length) throw new Error('Batch occurrence case IDs must be unique');
3991
+ if (config.reusePage && !config.shareBrowserContext) throw new Error('reusePage requires shareBrowserContext: true');
3992
+ if (config.reusePage && 1 !== config.concurrent) throw new Error('reusePage requires concurrent: 1');
3978
3993
  }
3979
3994
  }
3980
3995
  async function runYamlBatch(config, options = {}) {