is it possible to bypass the browsers custom dialog pop on browser/tab close?

I am new to react and im trying to trigger my own custom dialog component on tab/window close event.
I’ve checked everywhere and see that the usage of beforeunload is exactly what is needed to achieve this. However, when I add the beforeunload event listener, I see the browsers default leave site popup and only if I chose cancel on the dialog, then I see my custom dialog pop up appear.
can someone help me to achieve this functionality?