Is there a way to know withtin the sandboxed iframe when user is about to leave the top level window?

we have a custom app that uploads a video and we want to open a modal or sdk.dialog to alert users right before leaving the page [contentful web app]. Since the iframe containing our react custom app is sandboxed both are different, this poses a challenge that I don’t know how to solve yet. I’ve been playing around with postMessage API but I’m not getting too far with this. Ideally, I had thought we would open the modal window or sdk.dialog ‘onbeforeunload’ but that doesn’t even work inside the iframe. Does anyone have any idea on how to detect an ‘onbeforeunload’ event on the parent window from within the iframe? Have you gone through a similar case working with Contentful custom apps?