From 910776c0219a7eb8b00c95119dfe0f4d22d18d6f Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Tue, 23 Sep 2025 20:20:50 +0200 Subject: [PATCH] fix: remove unnecessary waiting for navigation --- src/McpContext.ts | 1 - src/WaitForHelper.ts | 20 ++++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/McpContext.ts b/src/McpContext.ts index 69143a18e..1456234ea 100644 --- a/src/McpContext.ts +++ b/src/McpContext.ts @@ -364,7 +364,6 @@ export class McpContext implements Context { const networkMultiplier = getNetworkMultiplierFromString( this.getNetworkConditions(), ); - const waitForHelper = this.getWaitForHelper( page, cpuMultiplier, diff --git a/src/WaitForHelper.ts b/src/WaitForHelper.ts index d9ff0f44c..281a95a45 100644 --- a/src/WaitForHelper.ts +++ b/src/WaitForHelper.ts @@ -126,18 +126,22 @@ export class WaitForHelper { async waitForEventsAfterAction( action: () => Promise, ): Promise { - const navigationStartedPromise = this.waitForNavigationStarted(); + const navigationFinished = this.waitForNavigationStarted() + .then(navigationStated => { + if (navigationStated) { + return this.#page.waitForNavigation({ + timeout: this.#navigationTimeout, + signal: this.#abortController.signal, + }); + } + return; + }) + .catch(error => logger(error)); await action(); try { - const navigationStated = await navigationStartedPromise; - if (navigationStated) { - await this.#page.waitForNavigation({ - timeout: this.#navigationTimeout, - signal: this.#abortController.signal, - }); - } + await navigationFinished; // Wait for stable dom after navigation so we execute in // the correct context