Skip to content

Commit 4bb8a34

Browse files
committed
fix: use native Proxy
1 parent 253168e commit 4bb8a34

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

packages/rrweb/src/record/observer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
legacy_isTouchEvent,
2020
StyleSheetMirror,
2121
nowTimestamp,
22+
getNativeProxy,
2223
} from '../utils';
2324
import { patch } from '@rrweb/utils';
2425
import type { observerParam, MutationBufferParam } from '../types';
@@ -58,6 +59,8 @@ import dom, { mutationObserverCtor } from '@rrweb/utils';
5859

5960
export const mutationBuffers: MutationBuffer[] = [];
6061

62+
const Proxy = getNativeProxy();
63+
6164
// Event.path is non-standard and used in some older browsers
6265
type NonStandardEvent = Omit<Event, 'composedPath'> & {
6366
path: EventTarget[];

packages/rrweb/src/utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,30 @@ export let _mirror: DeprecatedMirror = {
7373
console.error(DEPARTED_MIRROR_ACCESS_WARNING);
7474
},
7575
};
76+
77+
// Some libraries (i.e. jsPDF v1.1.135) override window.Proxy with their own implementation
78+
// Try to pull a clean implementation from a newly created iframe
79+
export function getNativeProxy(): ProxyConstructor {
80+
let Proxy = window.Proxy;
81+
try {
82+
if (
83+
typeof window.Proxy !== 'function' ||
84+
!window.Proxy?.toString().includes('[native code]')
85+
) {
86+
const cleanFrame = document.createElement('iframe');
87+
cleanFrame.style.display = 'none';
88+
document.documentElement.appendChild(cleanFrame);
89+
Proxy = (cleanFrame.contentWindow as Window & { Proxy: typeof Proxy })?.Proxy || window.Proxy;
90+
document.documentElement.removeChild(cleanFrame);
91+
}
92+
} catch (err) {
93+
console.debug('Unable to get native Proxy from iframe', err);
94+
}
95+
return Proxy;
96+
}
97+
7698
if (typeof window !== 'undefined' && window.Proxy && window.Reflect) {
99+
const Proxy = getNativeProxy();
77100
_mirror = new Proxy(_mirror, {
78101
get(target, prop, receiver) {
79102
if (prop === 'map') {

0 commit comments

Comments
 (0)