diff --git a/src/native-automation/request-pipeline/safe-api.ts b/src/native-automation/request-pipeline/safe-api.ts index 4153fe65ec1..ff19723196e 100644 --- a/src/native-automation/request-pipeline/safe-api.ts +++ b/src/native-automation/request-pipeline/safe-api.ts @@ -8,19 +8,21 @@ import ErrorReason = Protocol.Network.ErrorReason; import { isRequestPausedEvent } from '../utils/cdp'; import { ContinueRequestArgs, SessionId } from '../types'; -const INVALID_INTERCEPTED_RESPONSE_ERROR_MSG = 'Invalid InterceptionId.'; - -// In some cases (a request was aborted, any page that initiated the request doesn't exist, etc.) -// Chrome Debug Protocol doesn't allow to continue request pipeline -// and raises the "Invalid InterceptionId" error. -// We use the simplest way to fix it - omit such an error. +const IGNORED_ERROR_CODES = { + // In some cases (a request was aborted, any page that initiated the request doesn't exist, etc.) + // Chrome Debug Protocol doesn't allow to continue request pipeline + // and raises the "Invalid InterceptionId" error. + INVALID_INTERCEPTION_ID: -32602, + // The "Session not found" error can occur in iframes for unclear reasons. + SESSION_WITH_GIVEN_ID_NOT_FOUND: -32001, +}; async function connectionResetGuard (handleRequestFn: () => Promise, handleErrorFn: (err: any) => void): Promise { try { await handleRequestFn(); } catch (err: any) { - if (err.message === INVALID_INTERCEPTED_RESPONSE_ERROR_MSG) + if (Object.values(IGNORED_ERROR_CODES).includes(err?.response?.code)) return; handleErrorFn(err);