---
title: How do I end a session when the user refreshes their web page?
description: How do I end a session when the user refreshes their web page?
---

[Skip to content](https://support.cobrowse.io/how-do-i-end-a-session-on-web-page-refresh#main-content)

[![logo cobrowse purple.svg](https://support.cobrowse.io/hubfs/logo%20cobrowse%20purple.svg)](https://cobrowse.io/)

Open main navigation

Close main navigation

 How can we help you?

- There are no suggestions because the search field is empty.

1. [Knowledge Base](https://support.cobrowse.io/?hsLang=en)
2. [Web SDK questions](https://support.cobrowse.io/web-sdk-questions?hsLang=en)

# How do I end a session when the user refreshes their web page?

Please carefully consider whether this is the behaviour you require, as a consequence of doing this is that sessions will need to be restarted if the user refreshers their browser by mistake or for another reason.

The following code prevents the Cobrowse session continuing after a page refresh:

```
window.addEventListener("beforeunload", () => {  CobrowseIO.stop()}, {capture: true});
```

 This does not end the session but it prevents the agent from seeing the user’s screen. You can then end the session on the agent side using any of the [available methods](https://docs.cobrowse.io/agent-side-integrations/agent-sdk/faqs#end-the-session-after-a-chat-interaction-or-after-the-browser-is-closed).

- [Features overview](https://support.cobrowse.io/features-overview?hsLang=en)
- [Account management](https://support.cobrowse.io/account-management?hsLang=en)
- [User guides](https://support.cobrowse.io/user-guides?hsLang=en)
- [Cloud hosting (SaaS)](https://support.cobrowse.io/cloud-hosting-saas?hsLang=en)
- [Enterprise self-hosting](https://support.cobrowse.io/enterprise-self-hosting?hsLang=en)
- [Data privacy & security](https://support.cobrowse.io/data-privacy-security?hsLang=en)
- [Session data & recordings](https://support.cobrowse.io/session-data-recordings?hsLang=en)
- [Licenses & billing](https://support.cobrowse.io/licenses-billing?hsLang=en)
- [Web SDK questions](https://support.cobrowse.io/web-sdk-questions?hsLang=en)
- [Mobile SDKs questions](https://support.cobrowse.io/mobile-sdks-questions?hsLang=en)
- [Zendesk integration](https://support.cobrowse.io/zendesk-integration?hsLang=en)
- [Genesys Cloud integration](https://support.cobrowse.io/genesys-cloud-integration?hsLang=en)
- [Genesys Engage integration](https://support.cobrowse.io/genesys-engage-integration?hsLang=en)

[![Chill listening crop-3](https://support.cobrowse.io/hubfs/logo%20cobrowse%20purple-1.svg "Chill listening crop-3")](https://cobrowse.io/)

Cobrowse.io Knowledge Base

Copyright © 2026, Cobrowse.io LLC