Skip to content

Commit

Permalink
Ensure that setTimeout doesn't throw error for firefox extensions
Browse files Browse the repository at this point in the history
Whenever you do this kind of angular check for setTimeout, it ends
up causing problems in Firefox extensions:

TypeError: 'setTimeout' called on an object that does not implement interface Window

To avoid this you need to bind the setTimeout to the window
  • Loading branch information
colingm committed May 9, 2024
1 parent 31fa1f5 commit 7e3311f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export function getNative<T>(

export const nativeSetTimeout =
typeof window !== 'undefined'
? getNative<typeof window.setTimeout>('setTimeout')
? (getNative<typeof window.setTimeout>('setTimeout').bind(
window,
) as typeof window.setTimeout)
: global.setTimeout;

/**
Expand Down

0 comments on commit 7e3311f

Please sign in to comment.