@sentry/replay 7.51.2 → 7.52.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.js +497 -239
- package/cjs/index.js.map +1 -1
- package/esm/index.js +498 -240
- package/esm/index.js.map +1 -1
- package/package.json +5 -5
- package/types/coreHandlers/handleDom.d.ts +5 -2
- package/types/coreHandlers/handleDom.d.ts.map +1 -1
- package/types/coreHandlers/handleKeyboardEvent.d.ts +7 -0
- package/types/coreHandlers/handleKeyboardEvent.d.ts.map +1 -0
- package/types/coreHandlers/handleSlowClick.d.ts +12 -0
- package/types/coreHandlers/handleSlowClick.d.ts.map +1 -0
- package/types/coreHandlers/util/networkUtils.d.ts +2 -0
- package/types/coreHandlers/util/networkUtils.d.ts.map +1 -1
- package/types/replay.d.ts.map +1 -1
- package/types/types.d.ts +12 -0
- package/types/types.d.ts.map +1 -1
package/cjs/index.js
CHANGED
|
@@ -3264,6 +3264,475 @@ record.takeFullSnapshot = (isCheckout) => {
|
|
|
3264
3264
|
};
|
|
3265
3265
|
record.mirror = mirror;
|
|
3266
3266
|
|
|
3267
|
+
/**
|
|
3268
|
+
* Create a breadcrumb for a replay.
|
|
3269
|
+
*/
|
|
3270
|
+
function createBreadcrumb(
|
|
3271
|
+
breadcrumb,
|
|
3272
|
+
) {
|
|
3273
|
+
return {
|
|
3274
|
+
timestamp: Date.now() / 1000,
|
|
3275
|
+
type: 'default',
|
|
3276
|
+
...breadcrumb,
|
|
3277
|
+
};
|
|
3278
|
+
}
|
|
3279
|
+
|
|
3280
|
+
var NodeType;
|
|
3281
|
+
(function (NodeType) {
|
|
3282
|
+
NodeType[NodeType["Document"] = 0] = "Document";
|
|
3283
|
+
NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
|
|
3284
|
+
NodeType[NodeType["Element"] = 2] = "Element";
|
|
3285
|
+
NodeType[NodeType["Text"] = 3] = "Text";
|
|
3286
|
+
NodeType[NodeType["CDATA"] = 4] = "CDATA";
|
|
3287
|
+
NodeType[NodeType["Comment"] = 5] = "Comment";
|
|
3288
|
+
})(NodeType || (NodeType = {}));
|
|
3289
|
+
|
|
3290
|
+
/**
|
|
3291
|
+
* Converts a timestamp to ms, if it was in s, or keeps it as ms.
|
|
3292
|
+
*/
|
|
3293
|
+
function timestampToMs(timestamp) {
|
|
3294
|
+
const isMs = timestamp > 9999999999;
|
|
3295
|
+
return isMs ? timestamp : timestamp * 1000;
|
|
3296
|
+
}
|
|
3297
|
+
|
|
3298
|
+
/**
|
|
3299
|
+
* Add an event to the event buffer.
|
|
3300
|
+
* `isCheckout` is true if this is either the very first event, or an event triggered by `checkoutEveryNms`.
|
|
3301
|
+
*/
|
|
3302
|
+
async function addEvent(
|
|
3303
|
+
replay,
|
|
3304
|
+
event,
|
|
3305
|
+
isCheckout,
|
|
3306
|
+
) {
|
|
3307
|
+
if (!replay.eventBuffer) {
|
|
3308
|
+
// This implies that `_isEnabled` is false
|
|
3309
|
+
return null;
|
|
3310
|
+
}
|
|
3311
|
+
|
|
3312
|
+
if (replay.isPaused()) {
|
|
3313
|
+
// Do not add to event buffer when recording is paused
|
|
3314
|
+
return null;
|
|
3315
|
+
}
|
|
3316
|
+
|
|
3317
|
+
const timestampInMs = timestampToMs(event.timestamp);
|
|
3318
|
+
|
|
3319
|
+
// Throw out events that happen more than 5 minutes ago. This can happen if
|
|
3320
|
+
// page has been left open and idle for a long period of time and user
|
|
3321
|
+
// comes back to trigger a new session. The performance entries rely on
|
|
3322
|
+
// `performance.timeOrigin`, which is when the page first opened.
|
|
3323
|
+
if (timestampInMs + replay.timeouts.sessionIdlePause < Date.now()) {
|
|
3324
|
+
return null;
|
|
3325
|
+
}
|
|
3326
|
+
|
|
3327
|
+
try {
|
|
3328
|
+
if (isCheckout) {
|
|
3329
|
+
replay.eventBuffer.clear();
|
|
3330
|
+
}
|
|
3331
|
+
|
|
3332
|
+
return await replay.eventBuffer.addEvent(event);
|
|
3333
|
+
} catch (error) {
|
|
3334
|
+
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.error(error);
|
|
3335
|
+
await replay.stop('addEvent');
|
|
3336
|
+
|
|
3337
|
+
const client = core.getCurrentHub().getClient();
|
|
3338
|
+
|
|
3339
|
+
if (client) {
|
|
3340
|
+
client.recordDroppedEvent('internal_sdk_error', 'replay');
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3343
|
+
}
|
|
3344
|
+
|
|
3345
|
+
/**
|
|
3346
|
+
* Add a breadcrumb event to replay.
|
|
3347
|
+
*/
|
|
3348
|
+
function addBreadcrumbEvent(replay, breadcrumb) {
|
|
3349
|
+
if (breadcrumb.category === 'sentry.transaction') {
|
|
3350
|
+
return;
|
|
3351
|
+
}
|
|
3352
|
+
|
|
3353
|
+
if (['ui.click', 'ui.input'].includes(breadcrumb.category )) {
|
|
3354
|
+
replay.triggerUserActivity();
|
|
3355
|
+
} else {
|
|
3356
|
+
replay.checkAndHandleExpiredSession();
|
|
3357
|
+
}
|
|
3358
|
+
|
|
3359
|
+
replay.addUpdate(() => {
|
|
3360
|
+
void addEvent(replay, {
|
|
3361
|
+
type: EventType$1.Custom,
|
|
3362
|
+
// TODO: We were converting from ms to seconds for breadcrumbs, spans,
|
|
3363
|
+
// but maybe we should just keep them as milliseconds
|
|
3364
|
+
timestamp: (breadcrumb.timestamp || 0) * 1000,
|
|
3365
|
+
data: {
|
|
3366
|
+
tag: 'breadcrumb',
|
|
3367
|
+
// normalize to max. 10 depth and 1_000 properties per object
|
|
3368
|
+
payload: utils.normalize(breadcrumb, 10, 1000),
|
|
3369
|
+
},
|
|
3370
|
+
});
|
|
3371
|
+
|
|
3372
|
+
// Do not flush after console log messages
|
|
3373
|
+
return breadcrumb.category === 'console';
|
|
3374
|
+
});
|
|
3375
|
+
}
|
|
3376
|
+
|
|
3377
|
+
/**
|
|
3378
|
+
* Detect a slow click on a button/a tag,
|
|
3379
|
+
* and potentially create a corresponding breadcrumb.
|
|
3380
|
+
*/
|
|
3381
|
+
function detectSlowClick(
|
|
3382
|
+
replay,
|
|
3383
|
+
config,
|
|
3384
|
+
clickBreadcrumb,
|
|
3385
|
+
node,
|
|
3386
|
+
) {
|
|
3387
|
+
if (ignoreElement(node, config)) {
|
|
3388
|
+
return;
|
|
3389
|
+
}
|
|
3390
|
+
|
|
3391
|
+
/*
|
|
3392
|
+
We consider a slow click a click on a button/a, which does not trigger one of:
|
|
3393
|
+
- DOM mutation
|
|
3394
|
+
- Scroll (within 100ms)
|
|
3395
|
+
Within the given threshold time.
|
|
3396
|
+
After time timeout time, we stop listening and mark it as a slow click anyhow.
|
|
3397
|
+
*/
|
|
3398
|
+
|
|
3399
|
+
let cleanup = () => {
|
|
3400
|
+
// replaced further down
|
|
3401
|
+
};
|
|
3402
|
+
|
|
3403
|
+
// After timeout time, def. consider this a slow click, and stop watching for mutations
|
|
3404
|
+
const timeout = setTimeout(() => {
|
|
3405
|
+
handleSlowClick(replay, clickBreadcrumb, config.timeout, 'timeout');
|
|
3406
|
+
cleanup();
|
|
3407
|
+
}, config.timeout);
|
|
3408
|
+
|
|
3409
|
+
const mutationHandler = () => {
|
|
3410
|
+
maybeHandleSlowClick(replay, clickBreadcrumb, config.threshold, config.timeout, 'mutation');
|
|
3411
|
+
cleanup();
|
|
3412
|
+
};
|
|
3413
|
+
|
|
3414
|
+
const scrollHandler = () => {
|
|
3415
|
+
maybeHandleSlowClick(replay, clickBreadcrumb, config.scrollTimeout, config.timeout, 'scroll');
|
|
3416
|
+
cleanup();
|
|
3417
|
+
};
|
|
3418
|
+
|
|
3419
|
+
const obs = new MutationObserver(mutationHandler);
|
|
3420
|
+
|
|
3421
|
+
obs.observe(WINDOW.document.documentElement, {
|
|
3422
|
+
attributes: true,
|
|
3423
|
+
characterData: true,
|
|
3424
|
+
childList: true,
|
|
3425
|
+
subtree: true,
|
|
3426
|
+
});
|
|
3427
|
+
|
|
3428
|
+
WINDOW.addEventListener('scroll', scrollHandler);
|
|
3429
|
+
|
|
3430
|
+
// Stop listening to scroll timeouts early
|
|
3431
|
+
const scrollTimeout = setTimeout(() => {
|
|
3432
|
+
WINDOW.removeEventListener('scroll', scrollHandler);
|
|
3433
|
+
}, config.scrollTimeout);
|
|
3434
|
+
|
|
3435
|
+
cleanup = () => {
|
|
3436
|
+
clearTimeout(timeout);
|
|
3437
|
+
clearTimeout(scrollTimeout);
|
|
3438
|
+
obs.disconnect();
|
|
3439
|
+
WINDOW.removeEventListener('scroll', scrollHandler);
|
|
3440
|
+
};
|
|
3441
|
+
}
|
|
3442
|
+
|
|
3443
|
+
function maybeHandleSlowClick(
|
|
3444
|
+
replay,
|
|
3445
|
+
clickBreadcrumb,
|
|
3446
|
+
threshold,
|
|
3447
|
+
timeout,
|
|
3448
|
+
endReason,
|
|
3449
|
+
) {
|
|
3450
|
+
const now = Date.now();
|
|
3451
|
+
const timeAfterClickMs = now - clickBreadcrumb.timestamp * 1000;
|
|
3452
|
+
|
|
3453
|
+
if (timeAfterClickMs > threshold) {
|
|
3454
|
+
handleSlowClick(replay, clickBreadcrumb, Math.min(timeAfterClickMs, timeout), endReason);
|
|
3455
|
+
return true;
|
|
3456
|
+
}
|
|
3457
|
+
|
|
3458
|
+
return false;
|
|
3459
|
+
}
|
|
3460
|
+
|
|
3461
|
+
function handleSlowClick(
|
|
3462
|
+
replay,
|
|
3463
|
+
clickBreadcrumb,
|
|
3464
|
+
timeAfterClickMs,
|
|
3465
|
+
endReason,
|
|
3466
|
+
) {
|
|
3467
|
+
const breadcrumb = {
|
|
3468
|
+
message: clickBreadcrumb.message,
|
|
3469
|
+
timestamp: clickBreadcrumb.timestamp,
|
|
3470
|
+
category: 'ui.slowClickDetected',
|
|
3471
|
+
data: {
|
|
3472
|
+
...clickBreadcrumb.data,
|
|
3473
|
+
url: WINDOW.location.href,
|
|
3474
|
+
// TODO FN: add parametrized route, when possible
|
|
3475
|
+
timeAfterClickMs,
|
|
3476
|
+
endReason,
|
|
3477
|
+
},
|
|
3478
|
+
};
|
|
3479
|
+
|
|
3480
|
+
addBreadcrumbEvent(replay, breadcrumb);
|
|
3481
|
+
}
|
|
3482
|
+
|
|
3483
|
+
const SLOW_CLICK_IGNORE_TAGS = ['SELECT', 'OPTION'];
|
|
3484
|
+
|
|
3485
|
+
function ignoreElement(node, config) {
|
|
3486
|
+
// If <input> tag, we only want to consider input[type='submit'] & input[type='button']
|
|
3487
|
+
if (node.tagName === 'INPUT' && !['submit', 'button'].includes(node.getAttribute('type') || '')) {
|
|
3488
|
+
return true;
|
|
3489
|
+
}
|
|
3490
|
+
|
|
3491
|
+
if (SLOW_CLICK_IGNORE_TAGS.includes(node.tagName)) {
|
|
3492
|
+
return true;
|
|
3493
|
+
}
|
|
3494
|
+
|
|
3495
|
+
// If <a> tag, detect special variants that may not lead to an action
|
|
3496
|
+
// If target !== _self, we may open the link somewhere else, which would lead to no action
|
|
3497
|
+
// Also, when downloading a file, we may not leave the page, but still not trigger an action
|
|
3498
|
+
if (
|
|
3499
|
+
node.tagName === 'A' &&
|
|
3500
|
+
(node.hasAttribute('download') || (node.hasAttribute('target') && node.getAttribute('target') !== '_self'))
|
|
3501
|
+
) {
|
|
3502
|
+
return true;
|
|
3503
|
+
}
|
|
3504
|
+
|
|
3505
|
+
if (config.ignoreSelector && node.matches(config.ignoreSelector)) {
|
|
3506
|
+
return true;
|
|
3507
|
+
}
|
|
3508
|
+
|
|
3509
|
+
return false;
|
|
3510
|
+
}
|
|
3511
|
+
|
|
3512
|
+
// Note that these are the serialized attributes and not attributes directly on
|
|
3513
|
+
// the DOM Node. Attributes we are interested in:
|
|
3514
|
+
const ATTRIBUTES_TO_RECORD = new Set([
|
|
3515
|
+
'id',
|
|
3516
|
+
'class',
|
|
3517
|
+
'aria-label',
|
|
3518
|
+
'role',
|
|
3519
|
+
'name',
|
|
3520
|
+
'alt',
|
|
3521
|
+
'title',
|
|
3522
|
+
'data-test-id',
|
|
3523
|
+
'data-testid',
|
|
3524
|
+
]);
|
|
3525
|
+
|
|
3526
|
+
/**
|
|
3527
|
+
* Inclusion list of attributes that we want to record from the DOM element
|
|
3528
|
+
*/
|
|
3529
|
+
function getAttributesToRecord(attributes) {
|
|
3530
|
+
const obj = {};
|
|
3531
|
+
for (const key in attributes) {
|
|
3532
|
+
if (ATTRIBUTES_TO_RECORD.has(key)) {
|
|
3533
|
+
let normalizedKey = key;
|
|
3534
|
+
|
|
3535
|
+
if (key === 'data-testid' || key === 'data-test-id') {
|
|
3536
|
+
normalizedKey = 'testId';
|
|
3537
|
+
}
|
|
3538
|
+
|
|
3539
|
+
obj[normalizedKey] = attributes[key];
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3543
|
+
return obj;
|
|
3544
|
+
}
|
|
3545
|
+
|
|
3546
|
+
const handleDomListener = (
|
|
3547
|
+
replay,
|
|
3548
|
+
) => {
|
|
3549
|
+
const slowClickExperiment = replay.getOptions()._experiments.slowClicks;
|
|
3550
|
+
|
|
3551
|
+
const slowClickConfig = slowClickExperiment
|
|
3552
|
+
? {
|
|
3553
|
+
threshold: slowClickExperiment.threshold,
|
|
3554
|
+
timeout: slowClickExperiment.timeout,
|
|
3555
|
+
scrollTimeout: slowClickExperiment.scrollTimeout,
|
|
3556
|
+
ignoreSelector: slowClickExperiment.ignoreSelectors ? slowClickExperiment.ignoreSelectors.join(',') : '',
|
|
3557
|
+
}
|
|
3558
|
+
: undefined;
|
|
3559
|
+
|
|
3560
|
+
return (handlerData) => {
|
|
3561
|
+
if (!replay.isEnabled()) {
|
|
3562
|
+
return;
|
|
3563
|
+
}
|
|
3564
|
+
|
|
3565
|
+
const result = handleDom(handlerData);
|
|
3566
|
+
|
|
3567
|
+
if (!result) {
|
|
3568
|
+
return;
|
|
3569
|
+
}
|
|
3570
|
+
|
|
3571
|
+
const isClick = handlerData.name === 'click';
|
|
3572
|
+
const event = isClick && (handlerData.event );
|
|
3573
|
+
// Ignore clicks if ctrl/alt/meta keys are held down as they alter behavior of clicks (e.g. open in new tab)
|
|
3574
|
+
if (isClick && slowClickConfig && event && !event.altKey && !event.metaKey && !event.ctrlKey) {
|
|
3575
|
+
detectSlowClick(
|
|
3576
|
+
replay,
|
|
3577
|
+
slowClickConfig,
|
|
3578
|
+
result ,
|
|
3579
|
+
getClickTargetNode(handlerData.event) ,
|
|
3580
|
+
);
|
|
3581
|
+
}
|
|
3582
|
+
|
|
3583
|
+
addBreadcrumbEvent(replay, result);
|
|
3584
|
+
};
|
|
3585
|
+
};
|
|
3586
|
+
|
|
3587
|
+
/** Get the base DOM breadcrumb. */
|
|
3588
|
+
function getBaseDomBreadcrumb(target, message) {
|
|
3589
|
+
// `__sn` property is the serialized node created by rrweb
|
|
3590
|
+
const serializedNode = target && isRrwebNode(target) && target.__sn.type === NodeType.Element ? target.__sn : null;
|
|
3591
|
+
|
|
3592
|
+
return {
|
|
3593
|
+
message,
|
|
3594
|
+
data: serializedNode
|
|
3595
|
+
? {
|
|
3596
|
+
nodeId: serializedNode.id,
|
|
3597
|
+
node: {
|
|
3598
|
+
id: serializedNode.id,
|
|
3599
|
+
tagName: serializedNode.tagName,
|
|
3600
|
+
textContent: target
|
|
3601
|
+
? Array.from(target.childNodes)
|
|
3602
|
+
.map(
|
|
3603
|
+
(node) => '__sn' in node && node.__sn.type === NodeType.Text && node.__sn.textContent,
|
|
3604
|
+
)
|
|
3605
|
+
.filter(Boolean) // filter out empty values
|
|
3606
|
+
.map(text => (text ).trim())
|
|
3607
|
+
.join('')
|
|
3608
|
+
: '',
|
|
3609
|
+
attributes: getAttributesToRecord(serializedNode.attributes),
|
|
3610
|
+
},
|
|
3611
|
+
}
|
|
3612
|
+
: {},
|
|
3613
|
+
};
|
|
3614
|
+
}
|
|
3615
|
+
|
|
3616
|
+
/**
|
|
3617
|
+
* An event handler to react to DOM events.
|
|
3618
|
+
* Exported for tests.
|
|
3619
|
+
*/
|
|
3620
|
+
function handleDom(handlerData) {
|
|
3621
|
+
const { target, message } = getDomTarget(handlerData);
|
|
3622
|
+
|
|
3623
|
+
return createBreadcrumb({
|
|
3624
|
+
category: `ui.${handlerData.name}`,
|
|
3625
|
+
...getBaseDomBreadcrumb(target, message),
|
|
3626
|
+
});
|
|
3627
|
+
}
|
|
3628
|
+
|
|
3629
|
+
function getDomTarget(handlerData) {
|
|
3630
|
+
const isClick = handlerData.name === 'click';
|
|
3631
|
+
|
|
3632
|
+
let message;
|
|
3633
|
+
let target = null;
|
|
3634
|
+
|
|
3635
|
+
// Accessing event.target can throw (see getsentry/raven-js#838, #768)
|
|
3636
|
+
try {
|
|
3637
|
+
target = isClick ? getClickTargetNode(handlerData.event) : getTargetNode(handlerData.event);
|
|
3638
|
+
message = utils.htmlTreeAsString(target, { maxStringLength: 200 }) || '<unknown>';
|
|
3639
|
+
} catch (e) {
|
|
3640
|
+
message = '<unknown>';
|
|
3641
|
+
}
|
|
3642
|
+
|
|
3643
|
+
return { target, message };
|
|
3644
|
+
}
|
|
3645
|
+
|
|
3646
|
+
function isRrwebNode(node) {
|
|
3647
|
+
return '__sn' in node;
|
|
3648
|
+
}
|
|
3649
|
+
|
|
3650
|
+
function getTargetNode(event) {
|
|
3651
|
+
if (isEventWithTarget(event)) {
|
|
3652
|
+
return event.target ;
|
|
3653
|
+
}
|
|
3654
|
+
|
|
3655
|
+
return event;
|
|
3656
|
+
}
|
|
3657
|
+
|
|
3658
|
+
const INTERACTIVE_SELECTOR = 'button,a';
|
|
3659
|
+
|
|
3660
|
+
// For clicks, we check if the target is inside of a button or link
|
|
3661
|
+
// If so, we use this as the target instead
|
|
3662
|
+
// This is useful because if you click on the image in <button><img></button>,
|
|
3663
|
+
// The target will be the image, not the button, which we don't want here
|
|
3664
|
+
function getClickTargetNode(event) {
|
|
3665
|
+
const target = getTargetNode(event);
|
|
3666
|
+
|
|
3667
|
+
if (!target || !(target instanceof Element)) {
|
|
3668
|
+
return target;
|
|
3669
|
+
}
|
|
3670
|
+
|
|
3671
|
+
const closestInteractive = target.closest(INTERACTIVE_SELECTOR);
|
|
3672
|
+
return closestInteractive || target;
|
|
3673
|
+
}
|
|
3674
|
+
|
|
3675
|
+
function isEventWithTarget(event) {
|
|
3676
|
+
return typeof event === 'object' && !!event && 'target' in event;
|
|
3677
|
+
}
|
|
3678
|
+
|
|
3679
|
+
/** Handle keyboard events & create breadcrumbs. */
|
|
3680
|
+
function handleKeyboardEvent(replay, event) {
|
|
3681
|
+
if (!replay.isEnabled()) {
|
|
3682
|
+
return;
|
|
3683
|
+
}
|
|
3684
|
+
|
|
3685
|
+
replay.triggerUserActivity();
|
|
3686
|
+
|
|
3687
|
+
const breadcrumb = getKeyboardBreadcrumb(event);
|
|
3688
|
+
|
|
3689
|
+
if (!breadcrumb) {
|
|
3690
|
+
return;
|
|
3691
|
+
}
|
|
3692
|
+
|
|
3693
|
+
addBreadcrumbEvent(replay, breadcrumb);
|
|
3694
|
+
}
|
|
3695
|
+
|
|
3696
|
+
/** exported only for tests */
|
|
3697
|
+
function getKeyboardBreadcrumb(event) {
|
|
3698
|
+
const { metaKey, shiftKey, ctrlKey, altKey, key, target } = event;
|
|
3699
|
+
|
|
3700
|
+
// never capture for input fields
|
|
3701
|
+
if (!target || isInputElement(target )) {
|
|
3702
|
+
return null;
|
|
3703
|
+
}
|
|
3704
|
+
|
|
3705
|
+
// Note: We do not consider shift here, as that means "uppercase"
|
|
3706
|
+
const hasModifierKey = metaKey || ctrlKey || altKey;
|
|
3707
|
+
const isCharacterKey = key.length === 1; // other keys like Escape, Tab, etc have a longer length
|
|
3708
|
+
|
|
3709
|
+
// Do not capture breadcrumb if only a word key is pressed
|
|
3710
|
+
// This could leak e.g. user input
|
|
3711
|
+
if (!hasModifierKey && isCharacterKey) {
|
|
3712
|
+
return null;
|
|
3713
|
+
}
|
|
3714
|
+
|
|
3715
|
+
const message = utils.htmlTreeAsString(target, { maxStringLength: 200 }) || '<unknown>';
|
|
3716
|
+
const baseBreadcrumb = getBaseDomBreadcrumb(target , message);
|
|
3717
|
+
|
|
3718
|
+
return createBreadcrumb({
|
|
3719
|
+
category: 'ui.keyDown',
|
|
3720
|
+
message,
|
|
3721
|
+
data: {
|
|
3722
|
+
...baseBreadcrumb.data,
|
|
3723
|
+
metaKey,
|
|
3724
|
+
shiftKey,
|
|
3725
|
+
ctrlKey,
|
|
3726
|
+
altKey,
|
|
3727
|
+
key,
|
|
3728
|
+
},
|
|
3729
|
+
});
|
|
3730
|
+
}
|
|
3731
|
+
|
|
3732
|
+
function isInputElement(target) {
|
|
3733
|
+
return target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable;
|
|
3734
|
+
}
|
|
3735
|
+
|
|
3267
3736
|
const NAVIGATION_ENTRY_KEYS = [
|
|
3268
3737
|
'name',
|
|
3269
3738
|
'type',
|
|
@@ -3401,14 +3870,6 @@ function t(t){let e=t.length;for(;--e>=0;)t[e]=0}const e=new Uint8Array([0,0,0,0
|
|
|
3401
3870
|
|
|
3402
3871
|
function e(){const e=new Blob([r]);return URL.createObjectURL(e)}
|
|
3403
3872
|
|
|
3404
|
-
/**
|
|
3405
|
-
* Converts a timestamp to ms, if it was in s, or keeps it as ms.
|
|
3406
|
-
*/
|
|
3407
|
-
function timestampToMs(timestamp) {
|
|
3408
|
-
const isMs = timestamp > 9999999999;
|
|
3409
|
-
return isMs ? timestamp : timestamp * 1000;
|
|
3410
|
-
}
|
|
3411
|
-
|
|
3412
3873
|
/**
|
|
3413
3874
|
* A basic event buffer that does not do any compression.
|
|
3414
3875
|
* Used as fallback if the compression worker cannot be loaded or is disabled.
|
|
@@ -3986,53 +4447,6 @@ function getSession({
|
|
|
3986
4447
|
return { type: 'new', session: newSession };
|
|
3987
4448
|
}
|
|
3988
4449
|
|
|
3989
|
-
/**
|
|
3990
|
-
* Add an event to the event buffer.
|
|
3991
|
-
* `isCheckout` is true if this is either the very first event, or an event triggered by `checkoutEveryNms`.
|
|
3992
|
-
*/
|
|
3993
|
-
async function addEvent(
|
|
3994
|
-
replay,
|
|
3995
|
-
event,
|
|
3996
|
-
isCheckout,
|
|
3997
|
-
) {
|
|
3998
|
-
if (!replay.eventBuffer) {
|
|
3999
|
-
// This implies that `_isEnabled` is false
|
|
4000
|
-
return null;
|
|
4001
|
-
}
|
|
4002
|
-
|
|
4003
|
-
if (replay.isPaused()) {
|
|
4004
|
-
// Do not add to event buffer when recording is paused
|
|
4005
|
-
return null;
|
|
4006
|
-
}
|
|
4007
|
-
|
|
4008
|
-
const timestampInMs = timestampToMs(event.timestamp);
|
|
4009
|
-
|
|
4010
|
-
// Throw out events that happen more than 5 minutes ago. This can happen if
|
|
4011
|
-
// page has been left open and idle for a long period of time and user
|
|
4012
|
-
// comes back to trigger a new session. The performance entries rely on
|
|
4013
|
-
// `performance.timeOrigin`, which is when the page first opened.
|
|
4014
|
-
if (timestampInMs + replay.timeouts.sessionIdlePause < Date.now()) {
|
|
4015
|
-
return null;
|
|
4016
|
-
}
|
|
4017
|
-
|
|
4018
|
-
try {
|
|
4019
|
-
if (isCheckout) {
|
|
4020
|
-
replay.eventBuffer.clear();
|
|
4021
|
-
}
|
|
4022
|
-
|
|
4023
|
-
return await replay.eventBuffer.addEvent(event);
|
|
4024
|
-
} catch (error) {
|
|
4025
|
-
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.error(error);
|
|
4026
|
-
await replay.stop('addEvent');
|
|
4027
|
-
|
|
4028
|
-
const client = core.getCurrentHub().getClient();
|
|
4029
|
-
|
|
4030
|
-
if (client) {
|
|
4031
|
-
client.recordDroppedEvent('internal_sdk_error', 'replay');
|
|
4032
|
-
}
|
|
4033
|
-
}
|
|
4034
|
-
}
|
|
4035
|
-
|
|
4036
4450
|
/** If the event is an error event */
|
|
4037
4451
|
function isErrorEvent(event) {
|
|
4038
4452
|
return !event.type;
|
|
@@ -4118,187 +4532,6 @@ function isBaseTransportSend() {
|
|
|
4118
4532
|
);
|
|
4119
4533
|
}
|
|
4120
4534
|
|
|
4121
|
-
var NodeType;
|
|
4122
|
-
(function (NodeType) {
|
|
4123
|
-
NodeType[NodeType["Document"] = 0] = "Document";
|
|
4124
|
-
NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
|
|
4125
|
-
NodeType[NodeType["Element"] = 2] = "Element";
|
|
4126
|
-
NodeType[NodeType["Text"] = 3] = "Text";
|
|
4127
|
-
NodeType[NodeType["CDATA"] = 4] = "CDATA";
|
|
4128
|
-
NodeType[NodeType["Comment"] = 5] = "Comment";
|
|
4129
|
-
})(NodeType || (NodeType = {}));
|
|
4130
|
-
|
|
4131
|
-
/**
|
|
4132
|
-
* Create a breadcrumb for a replay.
|
|
4133
|
-
*/
|
|
4134
|
-
function createBreadcrumb(
|
|
4135
|
-
breadcrumb,
|
|
4136
|
-
) {
|
|
4137
|
-
return {
|
|
4138
|
-
timestamp: Date.now() / 1000,
|
|
4139
|
-
type: 'default',
|
|
4140
|
-
...breadcrumb,
|
|
4141
|
-
};
|
|
4142
|
-
}
|
|
4143
|
-
|
|
4144
|
-
/**
|
|
4145
|
-
* Add a breadcrumb event to replay.
|
|
4146
|
-
*/
|
|
4147
|
-
function addBreadcrumbEvent(replay, breadcrumb) {
|
|
4148
|
-
if (breadcrumb.category === 'sentry.transaction') {
|
|
4149
|
-
return;
|
|
4150
|
-
}
|
|
4151
|
-
|
|
4152
|
-
if (['ui.click', 'ui.input'].includes(breadcrumb.category )) {
|
|
4153
|
-
replay.triggerUserActivity();
|
|
4154
|
-
} else {
|
|
4155
|
-
replay.checkAndHandleExpiredSession();
|
|
4156
|
-
}
|
|
4157
|
-
|
|
4158
|
-
replay.addUpdate(() => {
|
|
4159
|
-
void addEvent(replay, {
|
|
4160
|
-
type: EventType$1.Custom,
|
|
4161
|
-
// TODO: We were converting from ms to seconds for breadcrumbs, spans,
|
|
4162
|
-
// but maybe we should just keep them as milliseconds
|
|
4163
|
-
timestamp: (breadcrumb.timestamp || 0) * 1000,
|
|
4164
|
-
data: {
|
|
4165
|
-
tag: 'breadcrumb',
|
|
4166
|
-
// normalize to max. 10 depth and 1_000 properties per object
|
|
4167
|
-
payload: utils.normalize(breadcrumb, 10, 1000),
|
|
4168
|
-
},
|
|
4169
|
-
});
|
|
4170
|
-
|
|
4171
|
-
// Do not flush after console log messages
|
|
4172
|
-
return breadcrumb.category === 'console';
|
|
4173
|
-
});
|
|
4174
|
-
}
|
|
4175
|
-
|
|
4176
|
-
// Note that these are the serialized attributes and not attributes directly on
|
|
4177
|
-
// the DOM Node. Attributes we are interested in:
|
|
4178
|
-
const ATTRIBUTES_TO_RECORD = new Set([
|
|
4179
|
-
'id',
|
|
4180
|
-
'class',
|
|
4181
|
-
'aria-label',
|
|
4182
|
-
'role',
|
|
4183
|
-
'name',
|
|
4184
|
-
'alt',
|
|
4185
|
-
'title',
|
|
4186
|
-
'data-test-id',
|
|
4187
|
-
'data-testid',
|
|
4188
|
-
]);
|
|
4189
|
-
|
|
4190
|
-
/**
|
|
4191
|
-
* Inclusion list of attributes that we want to record from the DOM element
|
|
4192
|
-
*/
|
|
4193
|
-
function getAttributesToRecord(attributes) {
|
|
4194
|
-
const obj = {};
|
|
4195
|
-
for (const key in attributes) {
|
|
4196
|
-
if (ATTRIBUTES_TO_RECORD.has(key)) {
|
|
4197
|
-
let normalizedKey = key;
|
|
4198
|
-
|
|
4199
|
-
if (key === 'data-testid' || key === 'data-test-id') {
|
|
4200
|
-
normalizedKey = 'testId';
|
|
4201
|
-
}
|
|
4202
|
-
|
|
4203
|
-
obj[normalizedKey] = attributes[key];
|
|
4204
|
-
}
|
|
4205
|
-
}
|
|
4206
|
-
|
|
4207
|
-
return obj;
|
|
4208
|
-
}
|
|
4209
|
-
|
|
4210
|
-
const handleDomListener =
|
|
4211
|
-
(replay) =>
|
|
4212
|
-
(handlerData) => {
|
|
4213
|
-
if (!replay.isEnabled()) {
|
|
4214
|
-
return;
|
|
4215
|
-
}
|
|
4216
|
-
|
|
4217
|
-
const result = handleDom(handlerData);
|
|
4218
|
-
|
|
4219
|
-
if (!result) {
|
|
4220
|
-
return;
|
|
4221
|
-
}
|
|
4222
|
-
|
|
4223
|
-
addBreadcrumbEvent(replay, result);
|
|
4224
|
-
};
|
|
4225
|
-
|
|
4226
|
-
/**
|
|
4227
|
-
* An event handler to react to DOM events.
|
|
4228
|
-
* Exported for tests only.
|
|
4229
|
-
*/
|
|
4230
|
-
function handleDom(handlerData) {
|
|
4231
|
-
let target;
|
|
4232
|
-
let targetNode;
|
|
4233
|
-
|
|
4234
|
-
const isClick = handlerData.name === 'click';
|
|
4235
|
-
|
|
4236
|
-
// Accessing event.target can throw (see getsentry/raven-js#838, #768)
|
|
4237
|
-
try {
|
|
4238
|
-
targetNode = isClick ? getClickTargetNode(handlerData.event) : getTargetNode(handlerData.event);
|
|
4239
|
-
target = utils.htmlTreeAsString(targetNode, { maxStringLength: 200 });
|
|
4240
|
-
} catch (e) {
|
|
4241
|
-
target = '<unknown>';
|
|
4242
|
-
}
|
|
4243
|
-
|
|
4244
|
-
// `__sn` property is the serialized node created by rrweb
|
|
4245
|
-
const serializedNode =
|
|
4246
|
-
targetNode && '__sn' in targetNode && targetNode.__sn.type === NodeType.Element ? targetNode.__sn : null;
|
|
4247
|
-
|
|
4248
|
-
return createBreadcrumb({
|
|
4249
|
-
category: `ui.${handlerData.name}`,
|
|
4250
|
-
message: target,
|
|
4251
|
-
data: serializedNode
|
|
4252
|
-
? {
|
|
4253
|
-
nodeId: serializedNode.id,
|
|
4254
|
-
node: {
|
|
4255
|
-
id: serializedNode.id,
|
|
4256
|
-
tagName: serializedNode.tagName,
|
|
4257
|
-
textContent: targetNode
|
|
4258
|
-
? Array.from(targetNode.childNodes)
|
|
4259
|
-
.map(
|
|
4260
|
-
(node) => '__sn' in node && node.__sn.type === NodeType.Text && node.__sn.textContent,
|
|
4261
|
-
)
|
|
4262
|
-
.filter(Boolean) // filter out empty values
|
|
4263
|
-
.map(text => (text ).trim())
|
|
4264
|
-
.join('')
|
|
4265
|
-
: '',
|
|
4266
|
-
attributes: getAttributesToRecord(serializedNode.attributes),
|
|
4267
|
-
},
|
|
4268
|
-
}
|
|
4269
|
-
: {},
|
|
4270
|
-
});
|
|
4271
|
-
}
|
|
4272
|
-
|
|
4273
|
-
function getTargetNode(event) {
|
|
4274
|
-
if (isEventWithTarget(event)) {
|
|
4275
|
-
return event.target;
|
|
4276
|
-
}
|
|
4277
|
-
|
|
4278
|
-
return event;
|
|
4279
|
-
}
|
|
4280
|
-
|
|
4281
|
-
const INTERACTIVE_SELECTOR = 'button,a';
|
|
4282
|
-
|
|
4283
|
-
// For clicks, we check if the target is inside of a button or link
|
|
4284
|
-
// If so, we use this as the target instead
|
|
4285
|
-
// This is useful because if you click on the image in <button><img></button>,
|
|
4286
|
-
// The target will be the image, not the button, which we don't want here
|
|
4287
|
-
function getClickTargetNode(event) {
|
|
4288
|
-
const target = getTargetNode(event);
|
|
4289
|
-
|
|
4290
|
-
if (!target || !(target instanceof Element)) {
|
|
4291
|
-
return target;
|
|
4292
|
-
}
|
|
4293
|
-
|
|
4294
|
-
const closestInteractive = target.closest(INTERACTIVE_SELECTOR);
|
|
4295
|
-
return closestInteractive || target;
|
|
4296
|
-
}
|
|
4297
|
-
|
|
4298
|
-
function isEventWithTarget(event) {
|
|
4299
|
-
return !!(event ).target;
|
|
4300
|
-
}
|
|
4301
|
-
|
|
4302
4535
|
/**
|
|
4303
4536
|
* Returns true if we think the given event is an error originating inside of rrweb.
|
|
4304
4537
|
*/
|
|
@@ -5216,7 +5449,32 @@ function _strIsProbablyJson(str) {
|
|
|
5216
5449
|
|
|
5217
5450
|
/** Match an URL against a list of strings/Regex. */
|
|
5218
5451
|
function urlMatches(url, urls) {
|
|
5219
|
-
|
|
5452
|
+
const fullUrl = getFullUrl(url);
|
|
5453
|
+
|
|
5454
|
+
return utils.stringMatchesSomePattern(fullUrl, urls);
|
|
5455
|
+
}
|
|
5456
|
+
|
|
5457
|
+
/** exported for tests */
|
|
5458
|
+
function getFullUrl(url, baseURI = WINDOW.document.baseURI) {
|
|
5459
|
+
// Short circuit for common cases:
|
|
5460
|
+
if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith(WINDOW.location.origin)) {
|
|
5461
|
+
return url;
|
|
5462
|
+
}
|
|
5463
|
+
const fixedUrl = new URL(url, baseURI);
|
|
5464
|
+
|
|
5465
|
+
// If these do not match, we are not dealing with a relative URL, so just return it
|
|
5466
|
+
if (fixedUrl.origin !== new URL(baseURI).origin) {
|
|
5467
|
+
return url;
|
|
5468
|
+
}
|
|
5469
|
+
|
|
5470
|
+
const fullUrl = fixedUrl.href;
|
|
5471
|
+
|
|
5472
|
+
// Remove trailing slashes, if they don't match the original URL
|
|
5473
|
+
if (!url.endsWith('/') && fullUrl.endsWith('/')) {
|
|
5474
|
+
return fullUrl.slice(0, -1);
|
|
5475
|
+
}
|
|
5476
|
+
|
|
5477
|
+
return fullUrl;
|
|
5220
5478
|
}
|
|
5221
5479
|
|
|
5222
5480
|
/**
|
|
@@ -7141,8 +7399,8 @@ class ReplayContainer {
|
|
|
7141
7399
|
};}
|
|
7142
7400
|
|
|
7143
7401
|
/** Ensure page remains active when a key is pressed. */
|
|
7144
|
-
__init16() {this._handleKeyboardEvent = () => {
|
|
7145
|
-
this
|
|
7402
|
+
__init16() {this._handleKeyboardEvent = (event) => {
|
|
7403
|
+
handleKeyboardEvent(this, event);
|
|
7146
7404
|
};}
|
|
7147
7405
|
|
|
7148
7406
|
/**
|