Skip to content

Commit

Permalink
Apply formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
billyvg authored and github-actions[bot] committed Jul 26, 2023
1 parent aaa0e91 commit 482de20
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 28 deletions.
7 changes: 6 additions & 1 deletion packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,12 @@ function serializeElementNode(
maskTextSelector,
unmaskTextSelector,
} = options;
const needBlock = _isBlockedElement(n, blockClass, blockSelector, unblockSelector);
const needBlock = _isBlockedElement(
n,
blockClass,
blockSelector,
unblockSelector,
);
const tagName = getValidTagName(n);
let attributes: attributes = {};
const len = n.attributes.length;
Expand Down
44 changes: 39 additions & 5 deletions packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,13 @@ export default class MutationBuffer {
case 'characterData': {
const value = m.target.textContent;
if (
!isBlocked(m.target, this.blockClass, this.blockSelector, this.unblockSelector, false) &&
!isBlocked(
m.target,
this.blockClass,
this.blockSelector,
this.unblockSelector,
false,
) &&
value !== m.oldValue
) {
this.texts.push({
Expand Down Expand Up @@ -558,7 +564,13 @@ export default class MutationBuffer {
});
}
if (
isBlocked(m.target, this.blockClass, this.blockSelector, this.unblockSelector, false) ||
isBlocked(
m.target,
this.blockClass,
this.blockSelector,
this.unblockSelector,
false,
) ||
value === m.oldValue
) {
return;
Expand Down Expand Up @@ -647,7 +659,15 @@ export default class MutationBuffer {
/**
* Parent is blocked, ignore all child mutations
*/
if (isBlocked(m.target, this.blockClass, this.blockSelector, this.unblockSelector, true)) {
if (
isBlocked(
m.target,
this.blockClass,
this.blockSelector,
this.unblockSelector,
true,
)
) {
return;
}

Expand All @@ -658,7 +678,13 @@ export default class MutationBuffer {
? this.mirror.getId(m.target.host)
: this.mirror.getId(m.target);
if (
isBlocked(m.target, this.blockClass, this.blockSelector, this.unblockSelector, false) ||
isBlocked(
m.target,
this.blockClass,
this.blockSelector,
this.unblockSelector,
false,
) ||
isIgnored(n, this.mirror) ||
!isSerialized(n, this.mirror)
) {
Expand Down Expand Up @@ -736,7 +762,15 @@ export default class MutationBuffer {

// if this node is blocked `serializeNode` will turn it into a placeholder element
// but we have to remove it's children otherwise they will be added as placeholders too
if (!isBlocked(n, this.blockClass, this.blockSelector, this.unblockSelector, false)) {
if (
!isBlocked(
n,
this.blockClass,
this.blockSelector,
this.unblockSelector,
false,
)
) {
n.childNodes.forEach((childN) => this.genAdds(childN));
if (hasShadowRoot(n)) {
n.shadowRoot.childNodes.forEach((childN) => {
Expand Down
57 changes: 50 additions & 7 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,27 @@ export function initScrollObserver({
sampling,
}: Pick<
observerParam,
'scrollCb' | 'doc' | 'mirror' | 'blockClass' | 'blockSelector' | 'unblockSelector' | 'sampling'
| 'scrollCb'
| 'doc'
| 'mirror'
| 'blockClass'
| 'blockSelector'
| 'unblockSelector'
| 'sampling'
>): listenerHandler {
const updatePosition = callbackWrapper(
throttle<UIEvent>(
callbackWrapper((evt) => {
const target = getEventTarget(evt);
if (
!target ||
isBlocked(target as Node, blockClass, blockSelector, unblockSelector, true)
isBlocked(
target as Node,
blockClass,
blockSelector,
unblockSelector,
true,
)
) {
return;
}
Expand Down Expand Up @@ -460,7 +472,13 @@ function initInputObserver({
!target ||
!tagName ||
INPUT_TAGS.indexOf(tagName) < 0 ||
isBlocked(target as Node, blockClass, blockSelector, unblockSelector, true)
isBlocked(
target as Node,
blockClass,
blockSelector,
unblockSelector,
true,
)
) {
return;
}
Expand Down Expand Up @@ -1089,7 +1107,13 @@ function initMediaInteractionObserver({
const target = getEventTarget(event);
if (
!target ||
isBlocked(target as Node, blockClass, blockSelector, unblockSelector, true)
isBlocked(
target as Node,
blockClass,
blockSelector,
unblockSelector,
true,
)
) {
return;
}
Expand Down Expand Up @@ -1181,7 +1205,14 @@ function initFontObserver({ fontCb, doc }: observerParam): listenerHandler {
}

function initSelectionObserver(param: observerParam): listenerHandler {
const { doc, mirror, blockClass, blockSelector, unblockSelector, selectionCb } = param;
const {
doc,
mirror,
blockClass,
blockSelector,
unblockSelector,
selectionCb,
} = param;
let collapsed = true;

const updateSelection = callbackWrapper(() => {
Expand All @@ -1200,8 +1231,20 @@ function initSelectionObserver(param: observerParam): listenerHandler {
const { startContainer, startOffset, endContainer, endOffset } = range;

const blocked =
isBlocked(startContainer, blockClass, blockSelector, unblockSelector, true) ||
isBlocked(endContainer, blockClass, blockSelector, unblockSelector, true);
isBlocked(
startContainer,
blockClass,
blockSelector,
unblockSelector,
true,
) ||
isBlocked(
endContainer,
blockClass,
blockSelector,
unblockSelector,
true,
);

if (blocked) continue;

Expand Down
10 changes: 9 additions & 1 deletion packages/rrweb/src/record/observers/canvas/2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ export default function initCanvas2DMutationObserver(
this: CanvasRenderingContext2D,
...args: Array<unknown>
) {
if (!isBlocked(this.canvas, blockClass, blockSelector, unblockSelector, true)) {
if (
!isBlocked(
this.canvas,
blockClass,
blockSelector,
unblockSelector,
true,
)
) {
// Using setTimeout as toDataURL can be heavy
// and we'd rather not block the main thread
setTimeout(() => {
Expand Down
24 changes: 19 additions & 5 deletions packages/rrweb/src/record/observers/canvas/canvas-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,23 @@ export class CanvasManager {
this.mirror = options.mirror;

if (recordCanvas && sampling === 'all')
this.initCanvasMutationObserver(win, blockClass, blockSelector, unblockSelector);
this.initCanvasMutationObserver(
win,
blockClass,
blockSelector,
unblockSelector,
);
if (recordCanvas && typeof sampling === 'number')
this.initCanvasFPSObserver(sampling, win, blockClass, blockSelector, unblockSelector, {
dataURLOptions,
});
this.initCanvasFPSObserver(
sampling,
win,
blockClass,
blockSelector,
unblockSelector,
{
dataURLOptions,
},
);
}

private processMutation: canvasManagerMutationCallback = (
Expand Down Expand Up @@ -169,7 +181,9 @@ export class CanvasManager {
const getCanvas = (): HTMLCanvasElement[] => {
const matchedCanvas: HTMLCanvasElement[] = [];
win.document.querySelectorAll('canvas').forEach((canvas) => {
if (!isBlocked(canvas, blockClass, blockSelector, unblockSelector, true)) {
if (
!isBlocked(canvas, blockClass, blockSelector, unblockSelector, true)
) {
matchedCanvas.push(canvas);
}
});
Expand Down
4 changes: 3 additions & 1 deletion packages/rrweb/src/record/observers/canvas/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export default function initCanvasContextObserver(
contextType: string,
...args: Array<unknown>
) {
if (!isBlocked(this, blockClass, blockSelector, unblockSelector, true)) {
if (
!isBlocked(this, blockClass, blockSelector, unblockSelector, true)
) {
if (!('__context' in this)) this.__context = contextType;
}
return original.apply(this, [contextType, ...args]);
Expand Down
10 changes: 9 additions & 1 deletion packages/rrweb/src/record/observers/canvas/webgl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ function patchGLPrototype(
return function (this: typeof prototype, ...args: Array<unknown>) {
const result = original.apply(this, args);
saveWebGLVar(result, win, this);
if (!isBlocked(this.canvas, blockClass, blockSelector, unblockSelector, true)) {
if (
!isBlocked(
this.canvas,
blockClass,
blockSelector,
unblockSelector,
true,
)
) {
const recordArgs = serializeArgs([...args], win, this);
const mutation: canvasMutationWithType = {
type,
Expand Down
12 changes: 10 additions & 2 deletions packages/rrweb/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import type {
DeprecatedMirror,
textMutation,
} from '@sentry-internal/rrweb-types';
import { createMatchPredicate, distanceToMatch, IMirror, Mirror } from '@sentry-internal/rrweb-snapshot';
import {
createMatchPredicate,
distanceToMatch,
IMirror,
Mirror,
} from '@sentry-internal/rrweb-snapshot';
import {
isShadowRoot,
IGNORED_NODE,
Expand Down Expand Up @@ -259,7 +264,10 @@ export function isBlocked(
}

if (unblockSelector) {
unblockDistance = distanceToMatch(el, createMatchPredicate(null, unblockSelector));
unblockDistance = distanceToMatch(
el,
createMatchPredicate(null, unblockSelector),
);
}

if (blockDistance > -1 && unblockDistance < 0) {
Expand Down
12 changes: 7 additions & 5 deletions packages/rrweb/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ describe('record integration tests', function (this: ISuite) {
const html = getHtml.call(this, 'unblock.html', {
blockSelector: 'div',
unblockSelector: '.rr-unblock',
})
});
await page.setContent(html);

await page.type('input', 'should be record');
Expand Down Expand Up @@ -559,10 +559,12 @@ describe('record integration tests', function (this: ISuite) {
it('mutations should work when blocked class is unblocked', async () => {
const page: puppeteer.Page = await browser.newPage();
await page.goto('about: blank');
await page.setContent(getHtml.call(this, 'blocked-unblocked.html', {
blockSelector: 'p',
unblockSelector: '.visible3,.rr-unblock',
}));
await page.setContent(
getHtml.call(this, 'blocked-unblocked.html', {
blockSelector: 'p',
unblockSelector: '.visible3,.rr-unblock',
}),
);

const elements1 = (await page.$x(
'/html/body/div[1]/button',
Expand Down

0 comments on commit 482de20

Please sign in to comment.