End session or Intimate agent side that customer closed the chat window

We have implemented the Genesys web messaging in a popup window which is opened when we click on the widget (custom button), the popup window will have registration form and upon clicking on start chat, the web messaging will load in to the popup window. My request here is, how can I end the session when the customer directly closes the popup window by pressing the (x) close button of the popup window. Because, currently when customer closes it the agent on the other side is unable to send any message to customer and agent is unaware that customer closed the popup window. Is there any unload event from genesys or any workaround for this? so that we can end the session or intimate the agent that customer closed the popup. window?

Note: This is not Headless mode SDK, this is developed using the Admin panel approach by creating the UI in the admin portal.