Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling `preventDefault` does not always have documented effect for `will-prevent-unload` events #20330

Open
amn opened this issue Sep 24, 2019 · 0 comments

Comments

@amn
Copy link

@amn amn commented Sep 24, 2019

Consider the following snippet run in the main process where one wants to listen for "will-prevent-default" events and after some asynchronous operation (do_something, a call which returns a Promise) initiated by the event listener, depending on the result (result) of the operation, call preventDefault on the event to allow page to unload:

/// Assume `win` refers to your typical application window (a `BrowserWindow` instance)
win.webContents.on("will-prevent-default", ev => {
    do_something().then(result => {
        if(result == some_value) {
            ev.preventDefault(); /// Does NOT work (page doesn't unload) when called from a callback, i.e. when not called immediately (synchronously) in the event handler.
        }
    });
    /// `ev.preventDefault` would have the documented effect if one placed the call here, e.g. somewhere it would be executed as part of the event handler itself, not a callback.
});

One would expect preventDefault to work as documented regardless of when it is called?

Is this a known issue, and is this simply a bug?

Electron 6.0.10 win32 x64
Microsoft Windows 10 64-bit Enterprise build 1709

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.