From ce968e0bc47d9c6f631bc9d158f0ada0a117468b Mon Sep 17 00:00:00 2001 From: uid11 Date: Tue, 3 Dec 2024 13:58:36 +0300 Subject: [PATCH] fix: ignore query parameters in re-requests --- src/utils/waitForEvents/isReRequest.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/utils/waitForEvents/isReRequest.ts b/src/utils/waitForEvents/isReRequest.ts index 0a182b3b..c3217a9c 100644 --- a/src/utils/waitForEvents/isReRequest.ts +++ b/src/utils/waitForEvents/isReRequest.ts @@ -1,3 +1,5 @@ +import {URL} from 'node:url'; + import type {RequestWithUtcTimeInMs} from '../../types/internal'; /** @@ -9,11 +11,25 @@ export const isReRequest = ( reRequest: RequestWithUtcTimeInMs, baseRequest: RequestWithUtcTimeInMs, ): boolean => { - if (reRequest.url !== baseRequest.url) { + if (reRequest.method !== baseRequest.method) { return false; } - if (reRequest.method !== baseRequest.method) { + const reRequestUrlObject = new URL(reRequest.url); + const baseRequestUrlObject = new URL(baseRequest.url); + + if (reRequestUrlObject.origin !== baseRequestUrlObject.origin) { + return false; + } + + if (reRequestUrlObject.search !== baseRequestUrlObject.search) { + return false; + } + + const reRequestQueryKeys = [...reRequestUrlObject.searchParams.keys()].join('&'); + const baseRequestQueryKeys = [...baseRequestUrlObject.searchParams.keys()].join('&'); + + if (reRequestQueryKeys !== baseRequestQueryKeys) { return false; }