2

Is there any event fired when the webContent zoom level is in/decreased or reset?

When I do a Zoom resize, using the default View menu items, the content is resized, but not the window size. And some of the content is no longer visible.

So I'm trying to manually adjust the window size when the content is resized.

Thanks

ferllings
  • 45
  • 5
  • Possible duplicate of [Catch browser's "zoom" event in JavaScript](https://stackoverflow.com/questions/995914/catch-browsers-zoom-event-in-javascript) – James Gould Sep 05 '18 at 09:47
  • As an Electron application is just an encapsulated web browser, you should be looking at how browsers handle this event. The flagged question above should tell you all you need to know (ie there is no way). – James Gould Sep 05 '18 at 09:47
  • Yes, but a browser doesn't resize itself when the content is resized. – ferllings Sep 05 '18 at 11:26

2 Answers2

0

Yes. A zoom-changed event is triggered. More details here -> https://github.com/electron/electron/pull/17747

Jhalaa Chinoy
  • 497
  • 5
  • 14
0

As far as I have gathered, the mentioned zoom-changed event is triggered only by pinch zooming, not when using the default View menu items. Instead, you could listen for the resize event, which is triggered also by changed zoom level. Of course, you would have to then check if the zoom level has actually changed, and act accordingly.

const { webFrame } = require("electron");

let prevZoomLevel = webFrame.getZoomLevel();

const onResize = () => {
  const newZoomLevel = webFrame.getZoomLevel();
  if (newZoomLevel !== prevZoomLevel) {
    // Do your thing
  }
  prevZoomLevel = newZoomLevel;
};

window.addEventListener('resize', onResize);