Is there an event listener or some kind of other way of finding out if a user has clicked the window close button on the browser or the refresh function of the browser?

I know about onunload and onbeforeunload, but I wondered if there is some kind of event listener that checks for this kind of thing?

Thanks! James