electron: system-context-menu prevents the default behavior from being invalid

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    • 11.0.3
  • Operating System:
    • Windows 10 (1803)
  • Last Known Working Electron version:

Expected Behavior

Prevent the default menu context from being displayed

Actual Behavior

image

To Reproduce

  • Set frame to true
  • Set -webkit-app-region: drag
  • Finally write the following code
win.on('system-context-menu', e => {
    e.preventDefault()
})

Screenshots

image

Additional Information

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 30 (11 by maintainers)

Commits related to this issue

Most upvoted comments

any fix ?

and i find a sideway , it works for me (just works and i didn’t know why )

const WM_INITMENU = 0x0116;
win.hookWindowMessage(WM_INITMENU, () => {
    win.setEnabled(false);
    win.setEnabled(true);
});

refers: https://github.com/electron/electron/issues/24893#issuecomment-1109262719

Still interested in this

I think a proper solution to this should still be provided.

The “system-context-menu” event is never triggered for me under Electron 11.0.3 and Windows 10, I’m using frame: false.

“system-context-menu” is still broken for me under Electron v12, it’s just not triggered.

Using Electron 16.0.4. This issue still persists. With frame: false the system-context-menu event is not triggered.

Thank you for your help, I have completed the effect I want, thank you!

@yangsen9608, you’re supposed to add the custom menu popup code inside the event handler, after the win.setEnabled(true); line. This works for me on the latest Electron version.