Skip to content

Chrome DevTools for coding agents

fix: remove unnecessary waiting for navigation (#83)

Alex Rudenko924c04249222
diff --git a/src/McpContext.ts b/src/McpContext.ts
index 69143a18..1456234e 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 d9ff0f44..281a95a4 100644
--- a/src/WaitForHelper.ts
+++ b/src/WaitForHelper.ts
@@ -126,18 +126,22 @@ export class WaitForHelper {
async waitForEventsAfterAction(
action: () => Promise<unknown>,
): Promise<void> {
- 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