new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Electron · API · all subjects

app/methods

526 notes in this subject, read out of this brain and free to use. This is page 7 of 9.

webFrame.findFrameByName(name)

Returns a WebFrame | null representing a child of webFrame with the supplied name string parameter. Returns null if there's no such frame or if the frame is not in the current renderer process.

webFrame.findFrameByRoutingId(routingId) deprecated

Returns a WebFrame | null that has the supplied routingId Integer parameter. Returns null if not found. Routing IDs can be retrieved from WebFrame instances (webFrame.routingId) and are also passed by frame specific WebContents navigation events (e.g. did-frame-navigate). This method is deprecated; use the new webFrame.findFrameByToken API instead.

webFrame.findFrameByToken(frameToken)

Returns a WebFrame | null that has the supplied frameToken string parameter. Returns null if not found. Frame tokens can be retrieved from WebFrame instances (webFrame.frameToken) and can also be retrieved from WebFrameMain instances using webFrameMain.frameToken.

webUtils.getPathForFile example with contextBridge

Example showing how to use webUtils.getPathForFile in a preload script exposed through contextBridge: // Renderer: const file = document.querySelector('input[type=file]').files[0] electronApi.doSomethingWithFile(file) // Preload script: const { contextBridge, webUtils } = require('electron') contextBridge.exposeInMainWorld('electronApi', { doSomethingWithFile (file) { const path = webUtils.getPathForFile(file) // Do something with the path, e.g., send it over IPC to the main process. // It's best not to expose the full file path to the web content if possible. } })

webUtils.getPathForFile method

webUtils.getPathForFile(file) takes a File parameter (a web File object) and returns a string. It returns the file system path that the File object points to. If the object passed in is not a File object, an exception is thrown. If the File object was constructed in JavaScript and is not backed by a file on disk, an empty string is returned. This method supersedes the previous augmentation to the File object with the path property.

webview.paste() method

Executes editing command paste in page.

webview.loadURL(url, options) method

Loads the url in the webview. The url must contain the protocol prefix, e.g. http:// or file://. Parameters: url (URL string), options (Object optional) with httpReferrer (string or Referrer structure, optional), userAgent (string, optional), extraHeaders (string, optional - extra headers separated by "\n"), postData (UploadRawData or UploadFile array, optional), baseURLForDataURL (string, optional - base url with trailing path separator for files to be loaded by data url). Returns Promise<void> that resolves when the page has finished loading (see did-finish-load event) and rejects if the page fails to load (see did-fail-load event).

webview.getURL() method

Returns string - The URL of guest page.

webview.getTitle() method

Returns string - The title of guest page.

webview.isLoading() method

Returns boolean - Whether guest page is still loading resources.

webview.stop() method

Stops any pending navigation.

webview.reload() method

Reloads the guest page.

webview.reloadIgnoringCache() method

Reloads the guest page and ignores cache.

webview.canGoBack() method

Returns boolean - Whether the guest page can go back.

webview.canGoForward() method

Returns boolean - Whether the guest page can go forward.

webview.canGoToOffset(offset) method

Parameters: offset (Integer). Returns boolean - Whether the guest page can go to offset.

webview.clearHistory() method

Clears the navigation history.

webview.goBack() method

Makes the guest page go back.

webview.executeJavaScript(code, userGesture) method

Parameters: code (string), userGesture (boolean, optional, default false). Returns Promise<any> that resolves with the result of the executed code or is rejected if the result of the code is a rejected promise. Evaluates code in page. If userGesture is set, it will create the user gesture context in the page. HTML APIs like requestFullScreen, which require user action, can take advantage of this option for automation.

webview.openDevTools() method

Opens a DevTools window for guest page.

webview.closeDevTools() method

Closes the DevTools window of guest page.

webview.isDevToolsOpened() method

Returns boolean - Whether guest page has a DevTools window attached.

webview.isDevToolsFocused() method

Returns boolean - Whether DevTools window of guest page is focused.

webview.inspectElement(x, y) method

Parameters: x (Integer), y (Integer). Starts inspecting element at position (x, y) of guest page.

webview.inspectServiceWorker() method

Opens the DevTools for the service worker context present in the guest page.

webview.setAudioMuted(muted) method

Parameters: muted (boolean). Set guest page muted.

webview.isAudioMuted() method

Returns boolean - Whether guest page has been muted.

webview.cut() method

Executes editing command cut in page.

webview.copy() method

Executes editing command copy in page.

webview.centerSelection() method

Centers the current text selection in page.

webview.goForward() method

Makes the guest page go forward.

webview.pasteAndMatchStyle() method

Executes editing command pasteAndMatchStyle in page.

webview.delete() method

Executes editing command delete in page.

webview.selectAll() method

Executes editing command selectAll in page.

webview.unselect() method

Executes editing command unselect in page.

webview.scrollToTop() method

Scrolls to the top of the current webview.

webview.scrollToBottom() method

Scrolls to the bottom of the current webview.

webview.adjustSelection(options) method

Parameters: options (Object) with start (Number, optional - amount to shift the start index of the current selection), end (Number, optional - amount to shift the end index of the current selection). Adjusts the current text selection starting and ending points in the focused frame by the given amounts. A negative amount moves the selection towards the beginning of the document, and a positive amount moves the selection towards the end of the document.

webview.replace(text) method

Parameters: text (string). Executes editing command replace in page.

webview.replaceMisspelling(text) method

Parameters: text (string). Executes editing command replaceMisspelling in page.

webview.insertText(text) method

Parameters: text (string). Returns Promise<void>. Inserts text to the focused element.

webview.print(options) method

Parameters: options (Object, optional) with silent (boolean, optional - don't ask user for print settings, default false), printBackground (boolean, optional - prints the background color and image of the web page, default false), deviceName (string, optional - set the printer device name to use, must be the system-defined name), color (boolean, optional - set whether the printed web page will be in color or grayscale, default true), margins (Object, optional) with marginType (string, optional - can be default, none, printableArea, or custom; if custom is chosen, you must also specify top, bottom, left, and right), top (number, optional - the top margin in pixels), bottom (number, optional - the bottom margin in pixels), left (number, optional - the left margin in pixels), right (number, optional - the right margin in pixels), landscape (boolean, optional - whether the web page should be printed in landscape mode, default false), scaleFactor (number, optional - the scale factor of the web page), pagesPerSheet (number, optional - the number of pages to print per page sheet), collate (boolean, optional - whether the web page should be collated), copies (number, optional - the number of copies of the web page to print), pageRanges (Object[] with from and to properties, optional - the page range to print), duplexMode (string, optional - set the duplex mode, can be simplex, shortEdge, or longEdge), dpi (Record<string, number>, optional) with horizontal (number, optional) and vertical (number, optional), header (string, optional - string to be printed as page header), footer (string, optional - string to be printed as page footer), pageSize (string or Size, optional - can be A3, A4, A5, Legal, Letter, Tabloid or an Object containing height in microns), usePrinterDefaultPageSize (boolean, optional - whether to use the system's default page size, default false). Returns Promise<void>. Prints webview's web page.

webview.printToPDF(options) method

Parameters: options (PrintToPDFOptions structure). Returns Promise<Uint8Array> that resolves with the generated PDF data. Prints webview's web page as PDF.

webview.capturePage(rect) method

Parameters: rect (Rectangle, optional - the area of the page to be captured). Returns Promise<NativeImage> that resolves with a NativeImage. Captures a snapshot of the page within rect. Omitting rect will capture the whole visible page.

webview.sendInputEvent(event) method

Parameters: event (MouseInputEvent or MouseWheelInputEvent or KeyboardInputEvent structure). Returns Promise<void>. Sends an input event to the page.

webview.setVisualZoomLevelLimits(minimumLevel, maximumLevel) method

Parameters: minimumLevel (number), maximumLevel (number). Returns Promise<void>. Sets the maximum and minimum pinch-to-zoom level.

webview.showDefinitionForSelection() method - macOS only

macOS only. Shows pop-up dictionary that searches the selected word on the page.

webview.getWebContentsId() method

Returns number - The WebContents ID of this webview.

webview.getUserAgent() method

Returns string - The user agent for guest page.

webview.setUserAgent(userAgent) method

Parameters: userAgent (string). Overrides the user agent for the guest page.

webview.goToOffset(offset) method

Parameters: offset (Integer). Navigates to the specified offset from the current entry.

webview.goToIndex(index) method

Parameters: index (Integer). Navigates to the specified absolute index.

setThumbarButtons Windows method

setThumbarButtons(buttons: ThumbarButton[]) is Windows-only. It adds a thumbnail toolbar with a specified set of buttons to the thumbnail image of a window in a taskbar button layout. Returns a boolean indicating whether the thumbnail has been added successfully. The number of buttons in thumbnail toolbar should be no greater than 7 due to the limited room. Once you setup the thumbnail toolbar, the toolbar cannot be removed due to the platform's limitation. But you can call the API with an empty array to clean the buttons. Each Button object has: icon (NativeImage) - the icon showing in thumbnail toolbar, click (Function), tooltip (string, optional) - the text of the button's tooltip, and flags (string[], optional) - control specific states and behaviors of the button. By default, flags is ['enabled']. Valid flag values are: enabled (the button is active and available to the user), disabled (the button is disabled, present but has a visual state indicating it will not respond to user action), dismissonclick (when the button is clicked, the thumbnail window closes immediately), nobackground (do not draw a button border, use only the image), hidden (the button is not shown to the user), and noninteractive (the button is enabled but not interactive; no pressed button state is drawn, intended for instances where the button is used in a notification).

BaseWindow constructor accepts BaseWindowConstructorOptions

BaseWindow is created with `new BaseWindow([options])` where options are of type BaseWindowConstructorOptions (optional).

BaseWindow.getAllWindows() static method

BaseWindow.getAllWindows() returns BaseWindow[] - an array of all opened browser windows.

BaseWindow.getFocusedWindow() static method

BaseWindow.getFocusedWindow() returns BaseWindow | null - the window that is focused in this application, or null if none.

BaseWindow.clearPersistedState() static method

BaseWindow.clearPersistedState(name) where name is a string (the window name to clear state for) clears the saved state for a window with the given name. This removes all persisted window bounds, display mode, and work area information that was previously saved when windowStatePersistence was enabled. If the window name is empty or the window state doesn't exist, the method will log a warning.

BaseWindow.setContentView() method

win.setContentView(view) where view is of type View sets the content view of the window.

BaseWindow.getContentView() method

win.getContentView() returns View - the content view of the window.

BaseWindow.destroy() method

win.destroy() force closes the window. The unload and beforeunload events won't be emitted for the web page, and the close event will also not be emitted for this window, but it guarantees the closed event will be emitted.

Give your agent this brain