From ef84f844ae6c0b1ef734b563e2eb8576718c1cb1 Mon Sep 17 00:00:00 2001 From: jackycoder Date: Sun, 20 Sep 2020 15:25:50 +0800 Subject: [PATCH] fix polyfill NodeList forEach (#357) --- src/replay/index.ts | 3 ++- src/utils.ts | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/replay/index.ts b/src/replay/index.ts index 1f74c447..95f7796a 100644 --- a/src/replay/index.ts +++ b/src/replay/index.ts @@ -102,7 +102,6 @@ export class Replayer { this.getCastFn = this.getCastFn.bind(this); this.emitter.on(ReplayerEvents.Resize, this.handleResize as Handler); - polyfill(); this.setupDom(); this.treeIndex = new TreeIndex(); @@ -330,6 +329,8 @@ export class Replayer { this.iframe.contentWindow, this.iframe.contentDocument, ); + + polyfill(this.iframe.contentWindow); } } diff --git a/src/utils.ts b/src/utils.ts index 2859ce4c..ee1924df 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -221,9 +221,9 @@ export function isTouchEvent( return Boolean((event as TouchEvent).changedTouches); } -export function polyfill() { - if ('NodeList' in window && !NodeList.prototype.forEach) { - NodeList.prototype.forEach = (Array.prototype +export function polyfill(win = window) { + if ('NodeList' in win && !win.NodeList.prototype.forEach) { + win.NodeList.prototype.forEach = (Array.prototype .forEach as unknown) as NodeList['forEach']; } }