Is there any document event to detect specifically window close and send current data with postMessage?

Given the following code

window.addEventListener("visibilitychange", () => {
   // do something here
    if (iframe)
            iframe.contentWindow.postMessage({
              type: "visit_close",
              page: document.title,
              time: timeSpentOnPage,
              shop: key,
              user: member_id,
            });
}

Is there any other reliable way to check if window is closing. Problem with visibilitychange event is that it gets fired on both load and unload.

As far as I remember, unload event is not reliable.