From 5a027bf7dc0f4f1d677d53de0ef6dbead55cd11f Mon Sep 17 00:00:00 2001 From: Roman Kuznetsov Date: Mon, 29 Dec 2025 15:58:44 +0300 Subject: [PATCH] fix: race condition with cdp mocks --- packages/webdriverio/src/utils/interception/devtools.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/webdriverio/src/utils/interception/devtools.ts b/packages/webdriverio/src/utils/interception/devtools.ts index d148894c8b4..6fd1dba27b1 100644 --- a/packages/webdriverio/src/utils/interception/devtools.ts +++ b/packages/webdriverio/src/utils/interception/devtools.ts @@ -37,6 +37,14 @@ export default class DevtoolsInterception extends Interception { static handleRequestInterception (client: CDPSession, mocks: Set): (event: Event) => Promise { return async (event) => { + // Race condition: if mock was already restored on client side + // But browser managed to send "Fetch.requestPaused" event before it received "Fetch.disable" + // Client-side "mocks" is already cleaned up, but browser is waiting for request instructions + // In this case we have to send "Fetch.continueRequest" to browser and do nothing more + if (!mocks) { + return client.send('Fetch.continueRequest', { requestId: event.requestId }).catch(/* istanbul ignore next */logFetchError) + } + // responseHeaders and responseStatusCode are only present in Response stage // https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#event-requestPaused const isRequest = !event.responseHeaders && !event.responseErrorReason