Skip to content

Commit 924c042

Browse files
authored
fix: remove unnecessary waiting for navigation (#83)
1 parent 67af3fe commit 924c042

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/McpContext.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ export class McpContext implements Context {
364364
const networkMultiplier = getNetworkMultiplierFromString(
365365
this.getNetworkConditions(),
366366
);
367-
368367
const waitForHelper = this.getWaitForHelper(
369368
page,
370369
cpuMultiplier,

src/WaitForHelper.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,22 @@ export class WaitForHelper {
126126
async waitForEventsAfterAction(
127127
action: () => Promise<unknown>,
128128
): Promise<void> {
129-
const navigationStartedPromise = this.waitForNavigationStarted();
129+
const navigationFinished = this.waitForNavigationStarted()
130+
.then(navigationStated => {
131+
if (navigationStated) {
132+
return this.#page.waitForNavigation({
133+
timeout: this.#navigationTimeout,
134+
signal: this.#abortController.signal,
135+
});
136+
}
137+
return;
138+
})
139+
.catch(error => logger(error));
130140

131141
await action();
132142

133143
try {
134-
const navigationStated = await navigationStartedPromise;
135-
if (navigationStated) {
136-
await this.#page.waitForNavigation({
137-
timeout: this.#navigationTimeout,
138-
signal: this.#abortController.signal,
139-
});
140-
}
144+
await navigationFinished;
141145

142146
// Wait for stable dom after navigation so we execute in
143147
// the correct context

0 commit comments

Comments
 (0)