fix polyfill NodeList forEach (#357)

This commit is contained in:
jackycoder
2020-09-20 15:25:50 +08:00
committed by GitHub
parent 64efb8c242
commit ef84f844ae
2 changed files with 5 additions and 4 deletions

View File

@@ -102,7 +102,6 @@ export class Replayer {
this.getCastFn = this.getCastFn.bind(this); this.getCastFn = this.getCastFn.bind(this);
this.emitter.on(ReplayerEvents.Resize, this.handleResize as Handler); this.emitter.on(ReplayerEvents.Resize, this.handleResize as Handler);
polyfill();
this.setupDom(); this.setupDom();
this.treeIndex = new TreeIndex(); this.treeIndex = new TreeIndex();
@@ -330,6 +329,8 @@ export class Replayer {
this.iframe.contentWindow, this.iframe.contentWindow,
this.iframe.contentDocument, this.iframe.contentDocument,
); );
polyfill(this.iframe.contentWindow);
} }
} }

View File

@@ -221,9 +221,9 @@ export function isTouchEvent(
return Boolean((event as TouchEvent).changedTouches); return Boolean((event as TouchEvent).changedTouches);
} }
export function polyfill() { export function polyfill(win = window) {
if ('NodeList' in window && !NodeList.prototype.forEach) { if ('NodeList' in win && !win.NodeList.prototype.forEach) {
NodeList.prototype.forEach = (Array.prototype win.NodeList.prototype.forEach = (Array.prototype
.forEach as unknown) as NodeList['forEach']; .forEach as unknown) as NodeList['forEach'];
} }
} }