From f8e88ced7b1def52a7f4126615a82866aeec28d7 Mon Sep 17 00:00:00 2001 From: jackycoder <295687784@qq.com> Date: Sun, 20 Sep 2020 18:55:29 +0800 Subject: [PATCH] compatibility fixes (#358) * fix polyfill NodeList forEach * contentDocument.contains for IE * polyfill DOMTokenList forEach --- src/replay/index.ts | 10 +++++++++- src/utils.ts | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/replay/index.ts b/src/replay/index.ts index 95f7796a..21be60cf 100644 --- a/src/replay/index.ts +++ b/src/replay/index.ts @@ -889,7 +889,15 @@ export class Replayer { return queue.push(mutation); } - const parentInDocument = this.iframe.contentDocument.contains(parent); + let parentInDocument = null; + if (this.iframe.contentDocument.contains) { + parentInDocument = this.iframe.contentDocument.contains(parent); + } else if (this.iframe.contentDocument.body.contains) { + // fix for IE + // refer 'Internet Explorer notes' at https://developer.mozilla.org/zh-CN/docs/Web/API/Document + parentInDocument = this.iframe.contentDocument.body.contains(parent); + } + if (useVirtualParent && parentInDocument) { const virtualParent = (document.createDocumentFragment() as unknown) as INode; mirror.map[mutation.parentId] = virtualParent; diff --git a/src/utils.ts b/src/utils.ts index ee1924df..9cf592d4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -226,6 +226,11 @@ export function polyfill(win = window) { win.NodeList.prototype.forEach = (Array.prototype .forEach as unknown) as NodeList['forEach']; } + + if ('DOMTokenList' in win && !win.DOMTokenList.prototype.forEach) { + win.DOMTokenList.prototype.forEach = (Array.prototype + .forEach as unknown) as DOMTokenList['forEach']; + } } export function needCastInSyncMode(event: eventWithTime): boolean {