Skip to content

Commit

Permalink
Md create html document (rrweb-io#1321)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
2 people authored and jxiwang committed Jul 31, 2024
1 parent 3bfcc54 commit b29bfca
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export default class MutationBuffer {
private shadowDomManager: observerParam['shadowDomManager'];
private canvasManager: observerParam['canvasManager'];
private processedNodeManager: observerParam['processedNodeManager'];
private unattachedDoc: HTMLDocument;

public init(options: MutationBufferParam) {
(
Expand Down Expand Up @@ -592,15 +593,17 @@ export default class MutationBuffer {
value,
);
if (attributeName === 'style') {
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;
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 = unattachedDoc.createElement('span');
const old = this.unattachedDoc.createElement('span');
if (m.oldValue) {
old.setAttribute('style', m.oldValue);
}
Expand Down

0 comments on commit b29bfca

Please sign in to comment.