Repository: electron
Issue: [Feature Request]: Possibility to set a default zoom level
Labels: enhancement :sparkles:

### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a feature request that matches the one I want to file, without success.

### Problem Description

I want to allow the users of my app to change the zoom level of the interface.

Currently, we have the possibility to change the zoom level using either [`setZoomLevel()`](https://www.electronjs.org/docs/latest/api/web-contents#contentssetzoomlevellevel) or [`setZoomFactor()`](https://www.electronjs.org/docs/latest/api/web-contents#contentssetzoomfactorfactor). They both seem to do the exact same thing.

The problem with these methods is that in they are only setting the zoom level for a single page. It's not a problem in development when `localhost` is used – since the zoom applies on the whole domain –, but in production it means the zoom resets back to default on any page that have not called the setter.

For example, here is what's setted in the `Preferences` file when calling `setZoomLevel()` on a `/settings` page:

```json
{
  "partition": {
    "per_host_zoom_levels": {
      "7076461166223254537": {
        "file:///[path-to-installed-app]/app.html#/settings": -0.5778829311823857
      }
    }
  }
}
```

The id `7076461166223254537` is auto generated and different for every app, I'm not sure what it represents.

On `#/settings`, the zoom is correctly applied with `-0.5xxx`, but if I navigate on another page, and then move or resize the window, the zoom resets back to `0` (and it get back to the custom zoom if I go on `settings`).

### Proposed Solution

Instead of setting `"per_host_zoom_levels"`, it's actually possible to change the zoom level for the whole app with `"default_zoom_level"`. In the `Preferences` file. It looks like this:

```json
{
  "partition": {
    "default_zoom_level": {
      "7076461166223254537": -0.5778829311823857
    }
  }
}
```

### Alternatives Considered

Instead of using the given API, I tried to edit the `Preferences` file with a custom code. However, there are two problems with this solution:

- First, I have no idea how to get the unique id, thus I have to call `setZoomLevel()` anyway to set a local zoom level in order to get the id to set the `"default_zoom_level"` property. Not a big problem but kinda meh for the perf.

- Second, the `Preferences` file seems to rewrite itself every time the window is moved or resized, and it erases any custom change I made to it. The only way I found for the setting to be preserved is to edit the `Preferences` file when the app is closed. I considered closing the app and relaunching it when the zoom setting is changed, but in my case the user is prompted to save their data before closing and they could do an action on the window reseting the `Preferences` before it's closed. Not only it could cause bugs, but it's also bad UX.

Finally, I also considered using CSS for zoom, but it breaks my whole UI.

### Additional Information

I tested all of this on Windows 10 & 11. Electron version 29.1.6.