Tutorial: PlatformProvider.getUserDecisionForBeforeUnload


Handle the decision of whether a Window or specific View should close when trying to prevent an unload. This is meant to be overridden. Called in PlatformProvider.closeWindow. Normally you would use this method to show a dialog indicating that there are Views that are trying to prevent an unload. By default it will flag for closing any Views passed into it.


const overrideCallback = (PlatformProvider) => {
    class Override extends PlatformProvider {
        async getUserDecisionForBeforeUnload(payload, callerIdentity) {
            const { windowShouldClose, viewsPreventingUnload, viewsNotPreventingUnload, windowId, closeType } = payload;

            // launch dialog and wait for user response
            const continueWithClose = await showDialog(viewsPreventingUnload, windowId, closeType);

            if (continueWithClose) {
                return { windowShouldClose, viewsToClose: [...viewsNotPreventingUnload, ...viewsPreventingUnload] };
            } else {
                return { windowShouldClose: false, viewsToClose: [] };
    return new Override();

fin.Platform.init({ overrideCallback });

async function showDialog(viewsPreventingUnload, windowId, closeType) {
    // Show a dialog and await for user response