Javascript callback for when a child window is closed in Chrome

We’ve a simple popup window that opens to a shop.app checkout page, and we’re trying to hook into when a user has navigated away from there/closed the window, to then query the api and update information in their profile, if the checkout was successful.

I’ve tried a few methods, but a lot of this seems to be old, old javascript that doesn’t seem to work “right” any more? Most topics on this are 10+ years old on here.

    const events = [
        "afterprint",
        "beforeprint",
        "beforeunload",
        "gamepadconnected",
        "gamepaddisconnected",
        "hashchange",
        "languagechange",
        "message",
        "messageerror",
        "offline",
        "online",
        "pagehide",
        "pageshow",
        "popstate",
        "rejectionhandled",
        "storage",
        "unhandledrejection",
        "unload"
      ]

    let proxy = window.open(
      buyUrl,
      "child",
      "toolbar=no,location=no,directories=no,status=no,menubar=no,titlebar=no,fullscreen=no,scrollbars=1,resizable=no,width=430,height=220,left=500,top=100"
    )
    const listener = (title: string) => (event: unknown) => {
      console.log(title, event)
    }

    if (proxy) {
      events.forEach((eventType) => {
        proxy.addEventListener(eventType, listener(eventType))
      })
      proxy.onbeforeunload = listener("rawbeforeunload")
      proxy.onmessage = listener("rawmessage")
      proxy.onclose = listener("rawclosed")
    }

I got the list of events above from the keys of the WindowEventHandlersEventMap interface, just to see if I wasn’t hooking into the right one. Only 2 events are triggered, pagehide and unload, but both of those basically happen at the very same time, and only at the very start of the window’s lifecycle, when the page is rendered.

I’d mainly just like to know when that window is closed from a callback, but obviously none of the above is working right for what I want.