My Electron application temporarily uses a WebContentsView, layered on top of part of the main window, during a login process. The user needs to interact with the web page in this view.
Simplified code to add the window is as follows:
const currentWindow = BaseWindow.getAllWindows()[0];
const web = new WebContentsView({webPreferences: { partition: 'temp-login' }});
currentWindow.contentView.addChildView(web);
web.setBounds({
x: 0,
y: 0,
width: currentWindow.getBounds().width - 16,
height: currentWindow.getBounds().height,
});
Running on Windows, this works OK, and I also added a resize handler so that the view is updated if the main window is resized.
However as you can probably see, I had to add a '-16' to allow room for a scrollbar, which seems to occur outside the bounds of the WebContentsView. Otherwise users can only scroll the view with mouse wheel; this is bad for usability.
I don't like this because 16 is probably not right on all platforms or depending on user settings or display type. Also what if the login web pages change so they aren't large enough to show a scrollbar.
Ideally there would be something like web.setOuterBounds, or some extra option to include along with the width, or whatever. But I tried searching the documentation & web and couldn't find it. Is there a better solution?