Skip to content

Unable to change zoom level on child windows #20084

Not planned
@zarubond

Description

@zarubond

I want to change the zoom level of child windows from main process, but it does not have any affect. Neither passing zoomFactor to BrowserWindow nor calling setZoomFactor on web contents work. Here is an example code where I try to change zoom factor on child window https://github.com/zarubond/electron-quick-start/tree/child_zoom

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:
    5.0.10, 6.0.2
  • Operating System:
    MacOS, Linux, Windows
  • Last Known Working Electron version:
    Never?

Expected Behavior

I should be able to change zoom factor of any window from main process

Actual Behavior

Any attempt to change it is ignored

To Reproduce

Try to change zoom factor of any child window

Activity

loc

loc commented on Sep 5, 2019

@loc
Contributor

The handler bound to ready-to-show is not running, so the webContents.setZoomFactor is never getting called. The handler isn't running because your window is immediately shown, so the event isn't emitted.

Relevant bit of docs, for reference:

While loading the page, the ready-to-show event will be emitted when the renderer process has rendered the page for the first time if the window has not been shown yet.

So, if you add a show: false to your BrowserWindow options and an event.newGuest.show() after ready-to-show, it should work as you expect.

One reason that it's not setting the zoomFactor when you initialize the BrowserWindow is that zoomFactor is a property of webPreferences, not of the top-level options type.

That being said, with zoomFactor correctly situated, you're still right, it doesn't work at BrowserWindow instantiation. It looks like this is because the native-window-opened webContents is already created by the time you intercept the new-window event, and Electron's zoom controller isn't updated when the webPreferences are merged at BrowserWindow creation.

11 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nornagon@loc@codebytere@sofianguy@zarubond

        Issue actions

          Unable to change zoom level on child windows · Issue #20084 · electron/electron