Electron.NET icon indicating copy to clipboard operation
Electron.NET copied to clipboard

Window Zoom Controls

Open AeonSake opened this issue 1 month ago • 15 comments

Is there currently any way to programmatically set/get the zoom level/factor of a window? I believe the electron side exposes a zoom API on the webFrame, but the BrowserWindow and WebContents classes currently don't provide any possibility to use it.

I understand that this might not be a very urgent feature, but it would be great to have nonetheless. Likewise, I would also gladly accept any alternative solution to get this to work.

AeonSake avatar Dec 02 '25 13:12 AeonSake

Is there any way to check the minimum supported version of this API or any Electron API for that matter?

agracio avatar Dec 02 '25 16:12 agracio

Good question; I don't think so? At least not directly. I would need to check the git history, but the zoom API has been part of electron since basically forever.

AeonSake avatar Dec 02 '25 16:12 AeonSake

Checking the electron GitHub history, it looks like the zoom API has been part of the shell since the start. The oldest entry I could find was with the creation of the initial documentation more than 11 years ago (webFrame was called webView back then).

AeonSake avatar Dec 02 '25 16:12 AeonSake

I can take a look at it later unless someone already picked that up. Are there any other known APIs that are either needed or nice to have?

agracio avatar Dec 02 '25 19:12 agracio

Personally, I can't say I'm missing any other APIs beside the zoom functions, but maybe the clearCache and insertText functions could also be useful to some? There are also some functions for spell-checker stuff on the webFrame class.

There are also a lot of other functions in the webContents class that I feel like might be more interesting; especially the undo/redo/copy/cut/etc. functions and the navigation functions.

AeonSake avatar Dec 02 '25 21:12 AeonSake

Would be great to have more APIs to finish at the same time, I will check for a few more and will get a PR ready in a day or two at most. If you can compile a list of some APIs with links that would be a great start, cannot promise that all will be done but will start with some low hanging fruits first.

But undo/redo/cut/copy/paste might be complicated to implement.

agracio avatar Dec 02 '25 21:12 agracio

Sure, I can compile you a list of all (relevant) functions with links. Priority is up to you, though, as I personally care mainly for the zoom API. Regarding the clipboard functions, as far as I understood it, those are just the browser-control calls which should then correctly map back to the clipboard API. Most functions on the webContents class seem to just provide an interface to native browser controls and content.

AeonSake avatar Dec 02 '25 22:12 AeonSake

After looking closely at the code it appears we do not have webFrame class at all. Will take longer to implement since it would require creation of a new class on both sides.

agracio avatar Dec 04 '25 12:12 agracio

Loading Content

Zoom

API for window zoom factor and limits. Changes the underlying rendering zoom, not the CSS styling zoom. Zoom factor of 1.0 = 100% (default). All of these methods are also available on the webFrame instance and I'm not entirely sure, how these interact with each other.

User Agent

Might be useful for some applications/websites that rely on user agent fingerprinting.

Dynamic CSS

Allows to manipulate CSS at runtime. All of these methods are also available on the webFrame instance.

Audio

Global audio/mute controls for the entire window.

Edit / Select

Access to the (usually browser) controls for the edit history and text selection. All copy/paste operations are executed with the clipboard API.

Dev Tools

Additional methods to control dev tools.

Cache Control

Resource Monitoring

AeonSake avatar Dec 04 '25 13:12 AeonSake

After looking closely at the code it appears we do not have webFrame class at all. Will take longer to implement since it would require creation of a new class on both sides.

The zoom API specifically exists on both, the webFrame and webContents instances. However, I'm not sure how they actually affect each other (i.e., is the zoom synchronized or inherited?). For now, I would say adding the webContents-specific methods to the already existing WebContents class on the C# side would probably be more than enough.

AeonSake avatar Dec 04 '25 13:12 AeonSake

Ok so I will be dropping webFrame for now. As for all the methods you mentioned I will implement some but definitely not all. Would be great if everyone else had a look at this list and gave some feedback.

agracio avatar Dec 04 '25 13:12 agracio

Yea, I feel like a lot of these methods are quite niche. I just tried to document most potentially relevant methods. Though personally, I would probably only add the zoom, the audio/mute, and maybe the dev tools and user agent stuff because they seem to be rather trivial for the implementation but still provide decent benefit for the user.

AeonSake avatar Dec 04 '25 14:12 AeonSake

Some are done and merged to develop https://github.com/ElectronNET/Electron.NET/pull/958. I might take a look at more once I have some time.

agracio avatar Dec 05 '25 10:12 agracio

There will be changes to property names to make them async, please hold on before using them in any implementation.

agracio avatar Dec 06 '25 11:12 agracio

Update: all properties will be removed, only methods will remain in code. See discussion in https://github.com/ElectronNET/Electron.NET/pull/958

agracio avatar Dec 06 '25 12:12 agracio