Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .changeset/eleven-bobcats-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'rrweb-snapshot': patch
'rrweb': patch
---

better support for coexistence with older libraries (e.g. MooTools & Prototype.js) which modify the in-built `Array.from` function
14 changes: 14 additions & 0 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ let takeFullSnapshot!: (isCheckout?: boolean) => void;
let canvasManager!: CanvasManager;
let recording = false;

// 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> = {},
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export type missingNodeMap = {
declare global {
interface Window {
FontFace: typeof FontFace;
Array: typeof Array;
}
}

Expand Down