1

I am showing web content in a BrowserView in Electron, and looking to allow pinch to zoom. I've tried the following that didn't work:

  view.webContents.setVisualZoomLevelLimits(1, 3)
  view.webContents.setLayoutZoomLevelLimits(1, 3)

Manually setting the zoom factor does seem to work:

view.webContents.setZoomFactor(3)

But nothing that I've tried can enable the user to zoom.

One thing confusing me is that in trying to search for the answer, everybody seems to have the opposite problem: Disable zooming (both pinch zoom and smart zoom [mac]) in electron https://github.com/electron/electron/issues/8793

So I'm wondering did something change? I am on electron 4.0.6, Node v11.12.0.

J Dan
  • 23
  • 1
  • 7

2 Answers2

1

Ok, I've found where they changed it: https://github.com/electron/electron/pull/12679

And others have this problem: https://github.com/electron/electron/issues/12631#issuecomment-447495983

Still trying to determine the exact fix.

J Dan
  • 23
  • 1
  • 7
0

You should call the setVisualZoomLevelLimits method on the webFrame object instead of on the webcontent. As is described here: https://github.com/electron/electron/issues/15417

In your renderer you should add:

webFrame.setVisualZoomLevelLimits(1, 4);