I am building an electron app and want to disable zoom behaviour coming from keyboard shortcuts (cmd +/- on mac).
The electron docs state that zoom is disabled by default, but I think that only applies to pinch-to-zoom behavior:
NOTE: Visual zoom is disabled by default in Electron.
https://www.electronjs.org/docs/api/web-frame#webframesetvisualzoomlevellimitsminimumlevel-maximumlevel
Other sources suggest using webFrame.setVisualZoomLevelLimits(1, 1)
but that doesn't seem to do the trick.
Am I missing something? Ideally would like to avoid manually listening on those specific keypress combinations in javascript.
Figured it out. The CMD +/- shortcuts get triggered because the application Menu by default includes MenuItems that have the roles zoomIn
and zoomOut
. If you don't want those behaviors in your application, you need to manually configure your menu.
There is an example of how to do that in the Electron docs, you just need to omit the 'zoomIn', 'zoomOut' and 'resetZoom' menuitems. https://www.electronjs.org/docs/latest/api/menu#examples