Skip to content

Commit 44fb19d

Browse files
Handle the case of xhr request + add a unit test for the case
1 parent eee77c1 commit 44fb19d

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

packages/replay/src/coreHandlers/util/xhrUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function _prepareXhrData(
7878
return null;
7979
}
8080

81-
if (!urlMatches(url, options.networkDetailAllowUrls)) {
81+
if (!urlMatches(url, options.networkDetailAllowUrls) || urlMatches(url, options.networkDetailExcludeUrls)) {
8282
const request = buildSkippedNetworkRequestOrResponse(requestBodySize);
8383
const response = buildSkippedNetworkRequestOrResponse(responseBodySize);
8484
return {

packages/replay/test/unit/coreHandlers/handleNetworkBreadcrumbs.test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,85 @@ other-header: test`;
14641464
},
14651465
]);
14661466
});
1467+
1468+
it('correctly excludes URL for xhr request', async () => {
1469+
options.networkDetailExcludeUrls = [
1470+
'https://example.com/foo',
1471+
'com/bar',
1472+
/^http:\/\/example.com\/exact$/,
1473+
/^http:\/\/example.com\/partial/,
1474+
];
1475+
1476+
const breadcrumb: Breadcrumb = {
1477+
category: 'xhr',
1478+
data: {
1479+
method: 'GET',
1480+
url,
1481+
status_code: 200,
1482+
},
1483+
};
1484+
const xhr = new XMLHttpRequest();
1485+
Object.defineProperty(xhr, 'response', {
1486+
value: 'test response',
1487+
});
1488+
Object.defineProperty(xhr, 'responseText', {
1489+
value: 'test response',
1490+
});
1491+
const hint: XhrBreadcrumbHint = {
1492+
xhr,
1493+
input: 'test input',
1494+
startTimestamp: BASE_TIMESTAMP + 1000,
1495+
endTimestamp: BASE_TIMESTAMP + 2000,
1496+
};
1497+
beforeAddNetworkBreadcrumb(options, breadcrumb, hint);
1498+
1499+
expect(breadcrumb).toEqual({
1500+
category: 'xhr',
1501+
data: {
1502+
method: 'GET',
1503+
request_body_size: 10,
1504+
response_body_size: 13,
1505+
status_code: 200,
1506+
url,
1507+
},
1508+
});
1509+
1510+
await waitForReplayEventBuffer();
1511+
1512+
expect((options.replay.eventBuffer as EventBufferArray).events).toEqual([
1513+
{
1514+
data: {
1515+
payload: {
1516+
data: {
1517+
method: 'GET',
1518+
request: {
1519+
_meta: {
1520+
warnings: ['URL_SKIPPED'],
1521+
},
1522+
headers: {},
1523+
size: 10,
1524+
},
1525+
response: {
1526+
_meta: {
1527+
warnings: ['URL_SKIPPED'],
1528+
},
1529+
headers: {},
1530+
size: 13,
1531+
},
1532+
statusCode: 200,
1533+
},
1534+
description: url,
1535+
endTimestamp: 1580598002,
1536+
op: 'resource.xhr',
1537+
startTimestamp: 1580598001,
1538+
},
1539+
tag: 'performanceSpan',
1540+
},
1541+
timestamp: 1580598001,
1542+
type: 5,
1543+
},
1544+
]);
1545+
});
14671546
});
14681547
});
14691548
});

0 commit comments

Comments
 (0)