Skip to content

Commit

Permalink
fix the Session with given id not found (closes #7865, #7810) (#7875)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev authored Jul 17, 2023
1 parent 36d8a88 commit aae15b6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/native-automation/request-pipeline/safe-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>, handleErrorFn: (err: any) => void): Promise<void> {
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);
Expand Down

0 comments on commit aae15b6

Please # to comment.