Returning text in beforeunload handler should prevent the close instead of allow the close.
Unlike normal browser which would show a dialog to choose whether to continue, you can just return a empty string in the handler to prevent unloading.