fix(tracker): typing, logs & remove duplicate sending
This commit is contained in:
parent
5d22cd3596
commit
3ad978e263
1 changed files with 10 additions and 18 deletions
|
|
@ -41,7 +41,7 @@ export default function (app: App | null) {
|
|||
const styleSheetIDMap: Map<CSSStyleSheet, number> = new Map()
|
||||
const adoptedStyleSheetsOwnings: Map<number, number[]> = 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue