File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import {
1919 legacy_isTouchEvent ,
2020 StyleSheetMirror ,
2121 nowTimestamp ,
22+ getNativeProxy ,
2223} from '../utils' ;
2324import { patch } from '@rrweb/utils' ;
2425import type { observerParam , MutationBufferParam } from '../types' ;
@@ -58,6 +59,8 @@ import dom, { mutationObserverCtor } from '@rrweb/utils';
5859
5960export const mutationBuffers : MutationBuffer [ ] = [ ] ;
6061
62+ const Proxy = getNativeProxy ( ) ;
63+
6164// Event.path is non-standard and used in some older browsers
6265type NonStandardEvent = Omit < Event , 'composedPath' > & {
6366 path : EventTarget [ ] ;
Original file line number Diff line number Diff 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+
7698if ( 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' ) {
You can’t perform that action at this time.
0 commit comments