stopRecording() to programmatically end the current recording session. Common reasons to reach for it:
- Logout flows — stop recording when the user signs out
- End of a workflow — close the session at the end of a multi-step flow so it shows up as a discrete recording in the dashboard
- Testing / QA tools — explicitly finalize a session without waiting for the page to unload
init() call starts a brand-new session.
- React
- JavaScript
- Script Tag
Use the
useMilana() hook:Return value
true if a session was active and has been torn down. false if there was no active session.Behavior
When you callstopRecording():
- The SDK sends a close signal to the server (
isClientAbort: truewithclientAbortReason: "CLIENT_STOPPED") so the session is finalized immediately rather than waiting for the backend’s inactivity timeout. - Any buffered events are flushed in the same request.
- Local rrweb recording, event observers, interval timers, and the
pagehidelistener are removed. sessionStorage.sessionIdis cleared so a subsequentinit()starts a brand-new session rather than resuming the one you just closed.
stopRecording() is idempotent — calling it when no session is active simply resolves with { success: false }.