Skip to content

Commit

Permalink
Merge branch 'main' into extension-audit
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi authored Aug 6, 2024
2 parents 182892c + faea531 commit 8f72904
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/content/services/monetizationTagManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,35 @@ export class MonetizationTagManager extends EventEmitter {
node.dispatchEvent(customEvent)
}

start(): void {
if (
document.readyState === 'interactive' ||
document.readyState === 'complete'
private isDocumentReady() {
return (
(document.readyState === 'interactive' ||
document.readyState === 'complete') &&
document.visibilityState === 'visible'
)
}

start(): void {
if (this.isDocumentReady()) {
this.run()
return
}

document.addEventListener(
'readystatechange',
() => {
if (document.readyState === 'interactive') {
if (this.isDocumentReady()) {
this.run()
} else {
document.addEventListener(
'visibilitychange',
() => {
if (this.isDocumentReady()) {
this.run()
}
},
{ once: true }
)
}
},
{ once: true }
Expand Down

0 comments on commit 8f72904

Please sign in to comment.