when-exit

Execute a function right before the process, or the browser's tab, is about to exit.

signal-exit

when you want to fire an event no matter how a process exits.