Repository navigation
Conversation
cee645a to
d39c98a
Compare
size-limit report 📦
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d39c98a. Configure here.
d39c98a to
670fcc8
Compare
c8aff48 to
91258cb
Compare
e86377c to
f166a90
Compare
f166a90 to
e8cefdc
Compare
e8cefdc to
e57d8b4
Compare
Also check on `freeze`/`resume` (Chromium only) and `pagehide`/`pageshow` (back/forward cache). This makes the time origin correction happen at the pause, not at the next regular timestamp call. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
e57d8b4 to
c70799b
Compare
| } | ||
|
|
||
| // Pages restored from the back/forward cache were paused while they were cached. | ||
| WINDOW.addEventListener?.('pagehide', () => timestampInSeconds()); | ||
| WINDOW.addEventListener?.('pageshow', () => timestampInSeconds()); | ||
|
|
||
| if (userInfo) { | ||
| this.on('beforeSendSession', addAutoIpAddressToSession); | ||
| } |
There was a problem hiding this comment.
Bug: New event listeners for freeze, resume, pagehide, and pageshow are not cleaned up when a BrowserClient is destroyed, causing a memory leak.
Severity: MEDIUM
Suggested Fix
Implement a cleanup mechanism in the BrowserClient. The client should track the listeners it adds. A close() or dispose() method should be implemented or overridden to remove these event listeners from the global objects when the client is destroyed, preventing old client instances from being retained in memory.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/browser/src/client.ts#L170-L178
Potential issue: The `BrowserClient` adds global event listeners for `freeze`, `resume`,
`pagehide`, and `pageshow`. However, there is no corresponding cleanup logic to remove
these listeners when a client instance is no longer needed. If multiple `BrowserClient`
instances are created over an application's lifecycle, such as during hot-reloading, in
test suites, or by calling `Sentry.init()` multiple times, old client instances and
their closures will be retained in memory. This leads to a memory leak, as the new
listeners introduced in this change are not removed upon client destruction.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
l: Should be easy to cleanup, no?

Follow-up to #23054, from this review comment. Besides
visibilitychange, we now also check for clock drift onfreeze/resume(TIL) andpagehide/pageshow. This way the time origin is corrected right at the emissions, not at the next regular timestamp call.freezeandresumeonly fire in Chromium. Other browsers never fire them, so the listeners do nothing there.