posthog-js
posthog-js copied to clipboard
Calling reset() can drop network captures
Bug description
A user wrote in that they are losing network captures after reset() is called. It looks like there's a chance we drop network captures due to a stale sessionID which puts the session recorder in a disabled state.
From lazy-loaded-session-recorder.ts:982-985
if (this.status === DISABLED) {
this._clearBuffer()
return
}
that early return might be the part causing the dropped events. No expert here so don't follow this too closely but tried to do some leg work if we wanted to improve this.
How to reproduce
- Start a session with network capture enabled
- Navigate and perform actions - network data is captured correctly
- Call posthog.reset() OR wait for session to expire
- Continue using the application WITHOUT refreshing the page
- Perform more actions that trigger network requests
- Check the session replay - the Network tab shows "There are no network requests in this recording" for all activities after the reset/expiration
Related sub-libraries
- [ ] All of them
- [x] posthog-js (web)
- [x] posthog-js-lite (web lite)
- [ ] posthog-node
- [ ] posthog-react-native
- [x] @posthog/react
- [ ] @posthog/ai
- [x] @posthog/nextjs-config
- [x] @posthog/nuxt
- [ ] @posthog/rollup-plugin
- [ ] @posthog/webpack-plugin