In a VF page, I can successfully hook into window.onbeforepageunload, but in LWCs and Lightning Components I am not really finding a way to do this.
In a Lightning Component hosted on a VisualForce page, I put a console.log in the unrender function and preserved my console through navigations. No log showed up when I navigated off the page.
In an LWC hosted on a VisualForce page, I put a console.log in the disconnectedCallback function and did not get any log when I navigated away from the page.
Is there anyway to detect the page changing or closing inside the LWC or Lightning Component and execute some javascript before it happens?