diff --git a/tracker/tracker/src/main/modules/constructedStyleSheets.ts b/tracker/tracker/src/main/modules/constructedStyleSheets.ts index acc662a64..a1289301e 100644 --- a/tracker/tracker/src/main/modules/constructedStyleSheets.ts +++ b/tracker/tracker/src/main/modules/constructedStyleSheets.ts @@ -41,7 +41,7 @@ export default function (app: App | null) { const styleSheetIDMap: Map = new Map() const adoptedStyleSheetsOwnings: Map = new Map() - const updateAdoptedStyleSheets = (root: StyleSheetOwner) => { + const sendAdoptedStyleSheetsUpdate = (root: StyleSheetOwner) => { let nodeID = app.nodes.getID(root) if (root === document) { nodeID = 0 // main document doesn't have nodeID. ID count starts from the documentElement @@ -93,7 +93,7 @@ export default function (app: App | null) { set: function (this: StyleSheetOwner, value) { // @ts-ignore const retVal = nativeAdoptedStyleSheetsDescriptor.set.call(this, value) - updateAdoptedStyleSheets(this) + sendAdoptedStyleSheetsUpdate(this) return retVal }, }) @@ -101,6 +101,12 @@ export default function (app: App | null) { } const patchContext = (context: typeof globalThis): void => { + // @ts-ignore + if (context.__openreplay_adpss_patched__) { + return + } else { + context.__openreplay_adpss_patched__ = true + } patchAdoptedStyleSheets(context.Document.prototype) patchAdoptedStyleSheets(context.ShadowRoot.prototype) @@ -125,20 +131,6 @@ export default function (app: App | null) { } return replaceSync.call(this, text) } - context.CSSStyleSheet.prototype.insertRule = function (rule: string, index = 0) { - const sheetID = styleSheetIDMap.get(this) - if (sheetID) { - app.send(AdoptedSSInsertRuleURLBased(sheetID, rule, index, app.getBaseHref())) - } - return insertRule.call(this, rule, index) - } - context.CSSStyleSheet.prototype.deleteRule = function (index: number) { - const sheetID = styleSheetIDMap.get(this) - if (sheetID) { - app.send(AdoptedSSDeleteRule(sheetID, index)) - } - return deleteRule.call(this, index) - } } patchContext(window) @@ -151,11 +143,11 @@ export default function (app: App | null) { // So far main Document is not triggered with nodeCallbacks app.attachStartCallback(() => { - updateAdoptedStyleSheets(document as StyleSheetOwner) + sendAdoptedStyleSheetsUpdate(document as StyleSheetOwner) }) app.nodes.attachNodeCallback((node: Node): void => { if (hasAdoptedSS(node)) { - updateAdoptedStyleSheets(node) + sendAdoptedStyleSheetsUpdate(node) } }) }