Md create html document (#1321)
* only call createHTMLDocument where it is needed * Perf: create the mutation document once as a 'singleton' as it can be reused --------- Co-authored-by: Michael Dellanoce <mdellanoce@pendo.io>
This commit is contained in:
@@ -190,6 +190,7 @@ export default class MutationBuffer {
|
|||||||
private shadowDomManager: observerParam['shadowDomManager'];
|
private shadowDomManager: observerParam['shadowDomManager'];
|
||||||
private canvasManager: observerParam['canvasManager'];
|
private canvasManager: observerParam['canvasManager'];
|
||||||
private processedNodeManager: observerParam['processedNodeManager'];
|
private processedNodeManager: observerParam['processedNodeManager'];
|
||||||
|
private unattachedDoc: HTMLDocument;
|
||||||
|
|
||||||
public init(options: MutationBufferParam) {
|
public init(options: MutationBufferParam) {
|
||||||
(
|
(
|
||||||
@@ -500,14 +501,6 @@ export default class MutationBuffer {
|
|||||||
if (isIgnored(m.target, this.mirror)) {
|
if (isIgnored(m.target, this.mirror)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let unattachedDoc;
|
|
||||||
try {
|
|
||||||
// avoid upsetting original document from a Content Security point of view
|
|
||||||
unattachedDoc = document.implementation.createHTMLDocument();
|
|
||||||
} catch (e) {
|
|
||||||
// fallback to more direct method
|
|
||||||
unattachedDoc = this.doc;
|
|
||||||
}
|
|
||||||
switch (m.type) {
|
switch (m.type) {
|
||||||
case 'characterData': {
|
case 'characterData': {
|
||||||
const value = m.target.textContent;
|
const value = m.target.textContent;
|
||||||
@@ -600,7 +593,17 @@ export default class MutationBuffer {
|
|||||||
value,
|
value,
|
||||||
);
|
);
|
||||||
if (attributeName === 'style') {
|
if (attributeName === 'style') {
|
||||||
const old = unattachedDoc.createElement('span');
|
if (!this.unattachedDoc) {
|
||||||
|
try {
|
||||||
|
// avoid upsetting original document from a Content Security point of view
|
||||||
|
this.unattachedDoc =
|
||||||
|
document.implementation.createHTMLDocument();
|
||||||
|
} catch (e) {
|
||||||
|
// fallback to more direct method
|
||||||
|
this.unattachedDoc = this.doc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const old = this.unattachedDoc.createElement('span');
|
||||||
if (m.oldValue) {
|
if (m.oldValue) {
|
||||||
old.setAttribute('style', m.oldValue);
|
old.setAttribute('style', m.oldValue);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user