Skip to content

Commit

Permalink
fix(background): prevent monetization at prerendering page
Browse files Browse the repository at this point in the history
  • Loading branch information
dianafulga committed Aug 6, 2024
1 parent e216ce1 commit b8f6a3c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/background/services/monetization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class MonetizationService {
)
return
}
const { tabId, frameId, url } = getSender(sender)
const { tabId, frameId, url, isPrerendering } = getSender(sender)
const sessions = this.tabState.getSessions(tabId)

const replacedSessions = new Set<string>()
Expand Down Expand Up @@ -95,6 +95,8 @@ export class MonetizationService {
sessions.set(requestId, session)
})

if (isPrerendering) return;

this.events.emit('monetization.state_update', tabId)

const sessionsArr = this.tabState.getEnabledSessions(tabId)
Expand Down
4 changes: 3 additions & 1 deletion src/background/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ export const getTab = (sender: Runtime.MessageSender): Tabs.Tab => {
export const getSender = (sender: Runtime.MessageSender) => {
const tabId = getTabId(sender)
const frameId = notNullOrUndef(sender.frameId, 'sender.frameId')
const isPrerendering = (sender as any).documentLifecycle === 'prerender' && sender.frameId !== 0;

return { tabId, frameId, url: sender.url }

return { tabId, frameId, url: sender.url, isPrerendering }
}

export const computeRate = (rate: string, sessionsCount: number): AmountValue =>
Expand Down

0 comments on commit b8f6a3c

Please sign in to comment.