Window Zoom Controls
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.
Is there any way to check the minimum supported version of this API or any Electron API for that matter?
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.
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).
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?
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.
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.
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.
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.
Loading Content
-
webContents.loadFile(filePath: string, options?: {query?: Record<string, string>, search?: string, hash?: string}) : Promise<void> -
webContents.isLoading() : boolean -
webContents.isLoadingMainFrame() : boolean -
webContents.isWaitingForResponse() : boolean -
webContents.reload() : void -
webContents.reloadIgnoringCache() : void -
webContents.stop() : void
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.
-
webContents.setZoomFactor(factor: double) : void- Factor must be greater than 0
-
webContents.getZoomFactor() : double -
webContents.setZoomLevel(level: number) : void- Zoom level and factor do the same thing but work slightly differently. The
levelstarts at 0 and each increment will increase/decrease the overall zoom by 20%. So a zoom level of 2 would be a total zoom of 140%, -1 would be 80%, etc.
- Zoom level and factor do the same thing but work slightly differently. The
-
webContents.getZoomLevel() : number -
webContents.setVisualZoomLevelLimits(minimumLevel: number, maximumLevel: number) : Promise<void> -
webContents.zoomFactor : double {get,set} -
webContents.zoomLevel : number {get,set}
User Agent
Might be useful for some applications/websites that rely on user agent fingerprinting.
-
webContents.setUserAgent(userAgent: string) : void -
webContents.getUserAgent() : string -
webContents.userAgent : string {get,set}
Dynamic CSS
Allows to manipulate CSS at runtime. All of these methods are also available on the webFrame instance.
-
webContents.insertCSS(css: string, options?: {cssOrigin?: string}) : Promise<string>- The returned value represents a unique key that can be used with
removeInsertedCSS()
- The returned value represents a unique key that can be used with
-
webContents.removeInsertedCSS(key: string) : Promise<void>
Audio
Global audio/mute controls for the entire window.
-
webContents.setAudioMuted(muted: boolean) : void -
webContents.isAudioMuted() : boolean -
webContents.isCurrentlyAudible() : boolean -
webContents.audioMuted : boolean {get,set}
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.
-
webContents.undo() : void -
webContents.redo() : void -
webContents.cut() : void -
webContents.copy() : void -
webContents.copyImageAt(x: int, y: int) : void -
webContents.paste() : void -
webContents.pasteAndMatchStyle() : void -
webContents.insertText(text: string) : void -
webContents.replace(text: string) : void -
webContents.replaceMisspelling(text: string) : void -
webContents.selectAll() : void -
webContents.unselect() : void -
webContents.adjustSelection(options: {start?: number, end?: number}) : void -
webContents.centerSelection() : void -
webContents.delete() : void -
webContents.findInPage(text: string, options?: {forward?: boolean, findNext?: boolean, matchCase?: boolean}) : int- The returned value is the ID of the request which is reported in the
found-in-pageevent.
- The returned value is the ID of the request which is reported in the
-
webContents.stopFindInPage(action: string) : void-
actionmust be one of the following:clearSelection,keepSelection,activateSelection
-
Dev Tools
Additional methods to control dev tools.
-
webContents.toggleDevTools() : void -
webContents.closeDevTools() : void -
webContents.isDevToolsOpened() : boolean -
webContents.isDevToolsFocused() : boolean
Cache Control
Resource Monitoring
After looking closely at the code it appears we do not have
webFrameclass 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.
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.
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.
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.
There will be changes to property names to make them async, please hold on before using them in any implementation.
Update: all properties will be removed, only methods will remain in code. See discussion in https://github.com/ElectronNET/Electron.NET/pull/958