Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce verbosity/redundancy of new pointerType attribute #1206

Merged
merged 9 commits into from
Apr 16, 2023
2 changes: 1 addition & 1 deletion .changeset/little-suits-leave.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
'@rrweb/types': minor
---

click events (as well as mousedown/mouseup/touchstart/touchend events) now include a `.pointerType` attribute which distinguishes between ['pen', 'mouse' and 'touch' events](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType)
click events now include a `.pointerType` attribute which distinguishes between ['pen', 'mouse' and 'touch' events](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType). There is no new PenDown/PenUp events, but these can be detected with a MouseDown/MouseUp + pointerType=pen
30 changes: 21 additions & 9 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,17 @@ function initMouseInteractionObserver({
let pointerType: PointerTypes | null = null;
let thisEventKey = eventKey;
if ('pointerType' in event) {
Object.keys(PointerTypes).forEach(
(pointerKey: keyof typeof PointerTypes) => {
if (event.pointerType === pointerKey.toLowerCase()) {
pointerType = PointerTypes[pointerKey];
return;
}
},
);
switch (event.pointerType) {
case 'mouse':
pointerType = PointerTypes.Mouse;
break;
case 'touch':
pointerType = PointerTypes.Touch;
break;
case 'pen':
pointerType = PointerTypes.Pen;
break;
}
if (pointerType === PointerTypes.Touch) {
if (MouseInteractions[eventKey] === MouseInteractions.MouseDown) {
// we are actually listening on 'pointerdown'
Expand All @@ -262,14 +265,23 @@ function initMouseInteractionObserver({
// we are actually listening on 'pointerup'
thisEventKey = 'TouchEnd';
}
} else if (pointerType == PointerTypes.Pen) {
} else if (pointerType === PointerTypes.Pen) {
// TODO: these will get incorrectly emitted as MouseDown/MouseUp
}
} else if (legacy_isTouchEvent(event)) {
pointerType = PointerTypes.Touch;
}
if (pointerType !== null) {
currentPointerType = pointerType;
if (
(thisEventKey.substring(0, 5) === 'Touch' &&
YunFeng0817 marked this conversation as resolved.
Show resolved Hide resolved
pointerType === PointerTypes.Touch) ||
(thisEventKey.substring(0, 5) === 'Mouse' &&
YunFeng0817 marked this conversation as resolved.
Show resolved Hide resolved
pointerType === PointerTypes.Mouse)
) {
// don't output redundant info
pointerType = null;
}
} else if (MouseInteractions[eventKey] === MouseInteractions.Click) {
pointerType = currentPointerType;
currentPointerType = null; // cleanup as we've used it
Expand Down
102 changes: 34 additions & 68 deletions packages/rrweb/test/__snapshots__/integration.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1529,17 +1529,15 @@ exports[`record integration tests can record clicks 1`] = `
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 18,
\\"pointerType\\": 0
\\"id\\": 18
}
},
{
\\"type\\": 3,
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 18,
\\"pointerType\\": 0
\\"id\\": 18
}
},
{
Expand All @@ -1556,17 +1554,15 @@ exports[`record integration tests can record clicks 1`] = `
\\"data\\": {
\\"source\\": 2,
\\"type\\": 7,
\\"id\\": 18,
\\"pointerType\\": 2
\\"id\\": 18
}
},
{
\\"type\\": 3,
\\"data\\": {
\\"source\\": 2,
\\"type\\": 9,
\\"id\\": 18,
\\"pointerType\\": 2
\\"id\\": 18
}
},
{
Expand All @@ -1583,8 +1579,7 @@ exports[`record integration tests can record clicks 1`] = `
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 21,
\\"pointerType\\": 0
\\"id\\": 21
}
},
{
Expand All @@ -1600,8 +1595,7 @@ exports[`record integration tests can record clicks 1`] = `
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 21,
\\"pointerType\\": 0
\\"id\\": 21
}
},
{
Expand Down Expand Up @@ -2135,8 +2129,7 @@ exports[`record integration tests can record form interactions 1`] = `
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 27,
\\"pointerType\\": 0
\\"id\\": 27
}
},
{
Expand All @@ -2160,8 +2153,7 @@ exports[`record integration tests can record form interactions 1`] = `
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 27,
\\"pointerType\\": 0
\\"id\\": 27
}
},
{
Expand Down Expand Up @@ -2196,8 +2188,7 @@ exports[`record integration tests can record form interactions 1`] = `
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 37,
\\"pointerType\\": 0
\\"id\\": 37
}
},
{
Expand All @@ -2221,8 +2212,7 @@ exports[`record integration tests can record form interactions 1`] = `
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 37,
\\"pointerType\\": 0
\\"id\\": 37
}
},
{
Expand Down Expand Up @@ -2915,8 +2905,7 @@ exports[`record integration tests can record node mutations 1`] = `
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 26,
\\"pointerType\\": 0
\\"id\\": 26
}
},
{
Expand Down Expand Up @@ -3373,8 +3362,7 @@ exports[`record integration tests can record node mutations 1`] = `
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 70,
\\"pointerType\\": 0
\\"id\\": 70
}
},
{
Expand Down Expand Up @@ -3921,8 +3909,7 @@ exports[`record integration tests can use maskInputOptions to configure which ty
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 27,
\\"pointerType\\": 0
\\"id\\": 27
}
},
{
Expand All @@ -3946,8 +3933,7 @@ exports[`record integration tests can use maskInputOptions to configure which ty
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 27,
\\"pointerType\\": 0
\\"id\\": 27
}
},
{
Expand Down Expand Up @@ -3982,8 +3968,7 @@ exports[`record integration tests can use maskInputOptions to configure which ty
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 37,
\\"pointerType\\": 0
\\"id\\": 37
}
},
{
Expand All @@ -4007,8 +3992,7 @@ exports[`record integration tests can use maskInputOptions to configure which ty
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 37,
\\"pointerType\\": 0
\\"id\\": 37
}
},
{
Expand Down Expand Up @@ -4972,8 +4956,7 @@ exports[`record integration tests mutations should work when blocked class is un
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 42,
\\"pointerType\\": 0
\\"id\\": 42
}
},
{
Expand All @@ -4989,8 +4972,7 @@ exports[`record integration tests mutations should work when blocked class is un
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 42,
\\"pointerType\\": 0
\\"id\\": 42
}
},
{
Expand Down Expand Up @@ -5098,8 +5080,7 @@ exports[`record integration tests mutations should work when blocked class is un
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 68,
\\"pointerType\\": 0
\\"id\\": 68
}
},
{
Expand All @@ -5123,8 +5104,7 @@ exports[`record integration tests mutations should work when blocked class is un
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 68,
\\"pointerType\\": 0
\\"id\\": 68
}
},
{
Expand Down Expand Up @@ -5692,8 +5672,7 @@ exports[`record integration tests should mask password value attribute with mask
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 20,
\\"pointerType\\": 0
\\"id\\": 20
}
},
{
Expand All @@ -5717,8 +5696,7 @@ exports[`record integration tests should mask password value attribute with mask
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 20,
\\"pointerType\\": 0
\\"id\\": 20
}
},
{
Expand Down Expand Up @@ -5803,8 +5781,7 @@ exports[`record integration tests should mask password value attribute with mask
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 20,
\\"pointerType\\": 0
\\"id\\": 20
}
},
{
Expand All @@ -5828,8 +5805,7 @@ exports[`record integration tests should mask password value attribute with mask
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 20,
\\"pointerType\\": 0
\\"id\\": 20
}
},
{
Expand Down Expand Up @@ -8537,8 +8513,7 @@ exports[`record integration tests should not record input values if maskAllInput
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 27,
\\"pointerType\\": 0
\\"id\\": 27
}
},
{
Expand All @@ -8562,8 +8537,7 @@ exports[`record integration tests should not record input values if maskAllInput
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 27,
\\"pointerType\\": 0
\\"id\\": 27
}
},
{
Expand Down Expand Up @@ -8598,8 +8572,7 @@ exports[`record integration tests should not record input values if maskAllInput
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 37,
\\"pointerType\\": 0
\\"id\\": 37
}
},
{
Expand All @@ -8623,8 +8596,7 @@ exports[`record integration tests should not record input values if maskAllInput
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 37,
\\"pointerType\\": 0
\\"id\\": 37
}
},
{
Expand Down Expand Up @@ -10574,17 +10546,15 @@ exports[`record integration tests should record dynamic CSS changes 1`] = `
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 26,
\\"pointerType\\": 0
\\"id\\": 26
}
},
{
\\"type\\": 3,
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 26,
\\"pointerType\\": 0
\\"id\\": 26
}
},
{
Expand Down Expand Up @@ -12255,8 +12225,7 @@ exports[`record integration tests should record input userTriggered values if us
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 27,
\\"pointerType\\": 0
\\"id\\": 27
}
},
{
Expand All @@ -12280,8 +12249,7 @@ exports[`record integration tests should record input userTriggered values if us
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 27,
\\"pointerType\\": 0
\\"id\\": 27
}
},
{
Expand Down Expand Up @@ -12318,8 +12286,7 @@ exports[`record integration tests should record input userTriggered values if us
\\"data\\": {
\\"source\\": 2,
\\"type\\": 1,
\\"id\\": 37,
\\"pointerType\\": 0
\\"id\\": 37
}
},
{
Expand All @@ -12343,8 +12310,7 @@ exports[`record integration tests should record input userTriggered values if us
\\"data\\": {
\\"source\\": 2,
\\"type\\": 0,
\\"id\\": 37,
\\"pointerType\\": 0
\\"id\\": 37
}
},
{
Expand Down
Loading