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

ref(rrweb): WIP: refactor sideeffects from rrweb/record #236

Draft
wants to merge 1 commit into
base: sentry-v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/rrweb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
"dist",
"package.json"
],
"sideEffects": false,
"sideEffects": [
"./src/record/clean-array-from.ts"
],
"author": "yanzhen@smartx.com",
"license": "MIT",
"bugs": {
Expand Down
15 changes: 15 additions & 0 deletions packages/rrweb/src/record/clean-array-from.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Multiple tools (i.e. MooTools, Prototype.js) override Array.from and drop support for the 2nd parameter
// Try to pull a clean implementation from a newly created iframe
try {
if (Array.from([1], (x) => x * 2)[0] !== 2) {
const cleanFrame = document.createElement('iframe');
document.body.appendChild(cleanFrame);
// eslint-disable-next-line @typescript-eslint/unbound-method -- Array.from is static and doesn't rely on binding
Array.from = cleanFrame.contentWindow?.Array.from || Array.from;
document.body.removeChild(cleanFrame);
}
} catch (err) {
console.debug('Unable to override Array.from', err);
}

export {};
25 changes: 9 additions & 16 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
MaskInputOptions,
SlimDOMOptions,
createMirror,
type Mirror,
} from '@sentry-internal/rrweb-snapshot';
import { initObservers, mutationBuffers } from './observer';
import {
Expand Down Expand Up @@ -52,6 +53,8 @@
registerErrorHandler,
unregisterErrorHandler,
} from './error-handler';
import './clean-array-from';

export type { CanvasManagerConstructorOptions } from './observers/canvas/canvas-manager';

declare global {
Expand All @@ -67,21 +70,6 @@
| ((e: eventWithTime, isCheckout?: boolean) => void);
let _takeFullSnapshot: undefined | ((isCheckout?: boolean) => void);

// Multiple tools (i.e. MooTools, Prototype.js) override Array.from and drop support for the 2nd parameter
// Try to pull a clean implementation from a newly created iframe
try {
if (Array.from([1], (x) => x * 2)[0] !== 2) {
const cleanFrame = document.createElement('iframe');
document.body.appendChild(cleanFrame);
// eslint-disable-next-line @typescript-eslint/unbound-method -- Array.from is static and doesn't rely on binding
Array.from = cleanFrame.contentWindow?.Array.from || Array.from;
document.body.removeChild(cleanFrame);
}
} catch (err) {
console.debug('Unable to override Array.from', err);
}

const mirror = createMirror();
function record<T = eventWithTime>(
options: recordOptions<T> = {},
): listenerHandler | undefined {
Expand Down Expand Up @@ -129,6 +117,7 @@
} = options;

registerErrorHandler(errorHandler);
const mirror = createMirror();

const inEmittingFrame = recordCrossOriginIframes
? window.parent === window
Expand Down Expand Up @@ -623,7 +612,7 @@
plugins
?.filter((p) => p.observer)
?.map((p) => ({
observer: p.observer!,

Check warning on line 615 in packages/rrweb/src/record/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion
options: p.options,
callback: (payload: object) =>
wrappedEmit({
Expand All @@ -641,7 +630,7 @@

iframeManager.addLoadListener((iframeEl) => {
try {
handlers.push(observe(iframeEl.contentDocument!));

Check warning on line 633 in packages/rrweb/src/record/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Forbidden non-null assertion
} catch (error) {
// TODO: handle internal error
console.warn(error);
Expand Down Expand Up @@ -721,9 +710,13 @@
// record.freezePage is removed because Sentry Session Replay does not use it

// For backwards compatibility - we can eventually remove this when we migrated to using the exported `mirror` & `takeFullSnapshot`
record.mirror = mirror;
// record.mirror = mirror;
record.takeFullSnapshot = takeFullSnapshot;

namespace record {

Check failure on line 716 in packages/rrweb/src/record/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

ES2015 module syntax is preferred over namespaces

Check failure on line 716 in packages/rrweb/src/record/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

ES2015 module syntax is preferred over namespaces
export var mirror: Mirror;

Check failure on line 717 in packages/rrweb/src/record/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Unexpected var, use let or const instead

Check failure on line 717 in packages/rrweb/src/record/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Check and Report Upload

Unexpected var, use let or const instead
}

export default record;

function _getCanvasManager(
Expand Down
Loading