Skip to content

ElectronWebContents

Unofficial

Electron WebContents for rendering and controlling a web page.

Note: the upstream static factories (fromId, fromDevToolsTargetId, getAllWebContents, getFocusedWebContents) cannot be expressed on a plain interface and are therefore omitted here.

Import:

import type { ElectronWebContents } from '@obsidian-typings/obsidian-public-latest';

Signature:

export interface ElectronWebContents

Properties

Property Type Description
audioMuted boolean Whether this page is muted.
backgroundThrottling boolean Whether this web contents throttles animations and timers when the page becomes backgrounded.
debugger ElectronDebugger The debugger instance for this web contents.
devToolsWebContents ElectronWebContents | null The DevTools web contents associated with this web contents, or null when DevTools is closed.
frameRate number The frame rate of the web contents. Only applicable when offscreen rendering is enabled.
hostWebContents ElectronWebContents The web contents that might own this web contents.
id number The unique id of this web contents.
mainFrame ElectronWebFrameMain The top frame of the page's frame hierarchy.
session Session The session used by this web contents.
userAgent string The user agent for this web page.
zoomFactor number The zoom factor for this web contents. The zoom factor is the zoom percent divided by 100.
zoomLevel number The zoom level for this web contents.

Methods

Method Returns Description
addListener(event, listener) this Registers a listener for the before-input-event event.
addListener(event, listener) this Registers a listener for the blur event.
addListener(event, listener) this Registers a listener for the certificate-error event.
addListener(event, listener) this Registers a listener for the console-message event.
addListener(event, listener) this Registers a listener for the context-menu event.
addListener(event, listener) this Registers a listener for the crashed event.
addListener(event, listener) this Registers a listener for the cursor-changed event.
addListener(event, listener) this Registers a listener for the destroyed event.
addListener(event, listener) this Registers a listener for the devtools-closed event.
addListener(event, listener) this Registers a listener for the devtools-focused event.
addListener(event, listener) this Registers a listener for the devtools-opened event.
addListener(event, listener) this Registers a listener for the devtools-reload-page event.
addListener(event, listener) this Registers a listener for the did-attach-webview event.
addListener(event, listener) this Registers a listener for the did-change-theme-color event.
addListener(event, listener) this Registers a listener for the did-create-window event.
addListener(event, listener) this Registers a listener for the did-fail-load event.
addListener(event, listener) this Registers a listener for the did-fail-provisional-load event.
addListener(event, listener) this Registers a listener for the did-finish-load event.
addListener(event, listener) this Registers a listener for the did-frame-finish-load event.
addListener(event, listener) this Registers a listener for the did-frame-navigate event.
addListener(event, listener) this Registers a listener for the did-navigate event.
addListener(event, listener) this Registers a listener for the did-navigate-in-page event.
addListener(event, listener) this Registers a listener for the did-redirect-navigation event.
addListener(event, listener) this Registers a listener for the did-start-loading event.
addListener(event, listener) this Registers a listener for the did-start-navigation event.
addListener(event, listener) this Registers a listener for the did-stop-loading event.
addListener(event, listener) this Registers a listener for the dom-ready event.
addListener(event, listener) this Registers a listener for the enter-html-full-screen event.
addListener(event, listener) this Registers a listener for the focus event.
addListener(event, listener) this Registers a listener for the found-in-page event.
addListener(event, listener) this Registers a listener for the frame-created event.
addListener(event, listener) this Registers a listener for the ipc-message event.
addListener(event, listener) this Registers a listener for the ipc-message-sync event.
addListener(event, listener) this Registers a listener for the leave-html-full-screen event.
addListener(event, listener) this Registers a listener for the login event.
addListener(event, listener) this Registers a listener for the media-paused event.
addListener(event, listener) this Registers a listener for the media-started-playing event.
addListener(event, listener) this Registers a listener for the new-window event.
addListener(event, listener) this Registers a listener for the page-favicon-updated event.
addListener(event, listener) this Registers a listener for the page-title-updated event.
addListener(event, listener) this Registers a listener for the paint event.
addListener(event, listener) this Registers a listener for the plugin-crashed event.
addListener(event, listener) this Registers a listener for the preferred-size-changed event.
addListener(event, listener) this Registers a listener for the preload-error event.
addListener(event, listener) this Registers a listener for the render-process-gone event.
addListener(event, listener) this Registers a listener for the responsive event.
addListener(event, listener) this Registers a listener for the select-bluetooth-device event.
addListener(event, listener) this Registers a listener for the select-client-certificate event.
addListener(event, listener) this Registers a listener for the unresponsive event.
addListener(event, listener) this Registers a listener for the update-target-url event.
addListener(event, listener) this Registers a listener for the will-attach-webview event.
addListener(event, listener) this Registers a listener for the will-navigate event.
addListener(event, listener) this Registers a listener for the will-prevent-unload event.
addListener(event, listener) this Registers a listener for the will-redirect event.
addListener(event, listener) this Registers a listener for the zoom-changed event.
addWorkSpace(path) void Adds the specified path to the DevTools workspace.
beginFrameSubscription(onlyDirty, callback) void Begins subscribing for presentation events and captured frames.
beginFrameSubscription(callback) void Begins subscribing for presentation events and captured frames.
canGoBack() boolean Returns whether the browser can go back to the previous web page.
canGoForward() boolean Returns whether the browser can go forward to the next web page.
canGoToOffset(offset) boolean Returns whether the web page can go to the given offset.
capturePage(rect?) Promise<ElectronNativeImage> Captures a snapshot of the page within rect. Omitting rect captures the whole visible page.
clearHistory() void Clears the navigation history.
closeDevTools() void Closes the developer tools.
copy() void Executes the editing command copy in the web page.
copyImageAt(x, y) void Copies the image at the given position to the clipboard.
cut() void Executes the editing command cut in the web page.
decrementCapturerCount(stayHidden?, stayAwake?) void Decreases the capturer count by one.
delete() void Executes the editing command delete in the web page.
disableDeviceEmulation() void Disables device emulation enabled by enableDeviceEmulation.
downloadURL(url) void Initiates a download of the resource at url without navigating.
enableDeviceEmulation(parameters) void Enables device emulation with the given parameters.
endFrameSubscription() void Ends subscribing for frame presentation events.
executeJavaScript(code, userGesture?) Promise<unknown> Evaluates code in the page.
executeJavaScriptInIsolatedWorld(worldId, scripts, userGesture?) Promise<unknown> Works like executeJavaScript but evaluates scripts in an isolated context.
findInPage(text, options?) number Starts a request to find all matches for text in the web page.
focus() void Focuses the web page.
forcefullyCrashRenderer() void Forcefully terminates the renderer process currently hosting this web contents.
getAllSharedWorkers() ElectronSharedWorkerInfo[] Returns information about all shared workers.
getBackgroundThrottling() boolean Returns whether this web contents throttles animations and timers when backgrounded.
getFrameRate() number Returns the current frame rate when offscreen rendering is enabled.
getMediaSourceId(requestWebContents) string Returns the identifier of a web contents stream.
getOSProcessId() number Returns the operating system pid of the associated renderer process.
getPrinters() ElectronPrinterInfo[] Returns the system printer list.
getPrintersAsync() Promise<ElectronPrinterInfo[]> Returns the system printer list.
getProcessId() number Returns the Chromium internal pid of the associated renderer.
getTitle() string Returns the title of the current web page.
getType() 'backgroundPage' | 'browserView' | 'offscreen' | 'remote' | 'webview' | 'window' Returns the type of the web contents.
getURL() string Returns the URL of the current web page.
getUserAgent() string Returns the user agent for this web page.
getWebRTCIPHandlingPolicy() string Returns the WebRTC IP handling policy.
getZoomFactor() number Returns the current zoom factor.
getZoomLevel() number Returns the current zoom level.
goBack() void Makes the browser go back a web page.
goForward() void Makes the browser go forward a web page.
goToIndex(index) void Navigates the browser to the specified absolute web page index.
goToOffset(offset) void Navigates to the specified offset from the current entry.
incrementCapturerCount(size?, stayHidden?, stayAwake?) void Increases the capturer count by one.
insertCSS(css, options?) Promise<string> Injects CSS into the current web page and returns a unique key for the inserted stylesheet.
insertText(text) Promise<void> Inserts text into the focused element.
inspectElement(x, y) void Starts inspecting the element at the given position.
inspectServiceWorker() void Opens the developer tools for the service worker context.
inspectSharedWorker() void Opens the developer tools for the shared worker context.
inspectSharedWorkerById(workerId) void Inspects the shared worker based on its id.
invalidate() void Schedules a full repaint of the window this web contents is in.
isAudioMuted() boolean Returns whether this page has been muted.
isBeingCaptured() boolean Returns whether this page is being captured.
isCrashed() boolean Returns whether the renderer process has crashed.
isCurrentlyAudible() boolean Returns whether audio is currently playing.
isDestroyed() boolean Returns whether the web page is destroyed.
isDevToolsFocused() boolean Returns whether the DevTools view is focused.
isDevToolsOpened() boolean Returns whether the DevTools is opened.
isFocused() boolean Returns whether the web page is focused.
isLoading() boolean Returns whether the web page is still loading resources.
isLoadingMainFrame() boolean Returns whether the main frame is still loading.
isOffscreen() boolean Returns whether offscreen rendering is enabled.
isPainting() boolean Returns whether it is currently painting when offscreen rendering is enabled.
isWaitingForResponse() boolean Returns whether the web page is waiting for a first response from the main resource.
loadFile(filePath, options?) Promise<void> Loads the given file in the window.
loadURL(url, options?) Promise<void> Loads the url in the window.
on('before-input-event', listener) this Registers a listener for the before-input-event event.
on('blur', listener) this Registers a listener for the blur event.
on('certificate-error', listener) this Registers a listener for the certificate-error event.
on('console-message', listener) this Registers a listener for the console-message event.
on('context-menu', listener) this Registers a listener for the context-menu event.
on('crashed', listener) this Registers a listener for the crashed event.
on('cursor-changed', listener) this Registers a listener for the cursor-changed event.
on('destroyed', listener) this Registers a listener for the destroyed event.
on('devtools-closed', listener) this Registers a listener for the devtools-closed event.
on('devtools-focused', listener) this Registers a listener for the devtools-focused event.
on('devtools-opened', listener) this Registers a listener for the devtools-opened event.
on('devtools-reload-page', listener) this Registers a listener for the devtools-reload-page event.
on('did-attach-webview', listener) this Registers a listener for the did-attach-webview event.
on('did-change-theme-color', listener) this Registers a listener for the did-change-theme-color event.
on('did-create-window', listener) this Registers a listener for the did-create-window event.
on('did-fail-load', listener) this Registers a listener for the did-fail-load event.
on('did-fail-provisional-load', listener) this Registers a listener for the did-fail-provisional-load event.
on('did-finish-load', listener) this Registers a listener for the did-finish-load event.
on('did-frame-finish-load', listener) this Registers a listener for the did-frame-finish-load event.
on('did-frame-navigate', listener) this Registers a listener for the did-frame-navigate event.
on('did-navigate', listener) this Registers a listener for the did-navigate event.
on('did-navigate-in-page', listener) this Registers a listener for the did-navigate-in-page event.
on('did-redirect-navigation', listener) this Registers a listener for the did-redirect-navigation event.
on('did-start-loading', listener) this Registers a listener for the did-start-loading event.
on('did-start-navigation', listener) this Registers a listener for the did-start-navigation event.
on('did-stop-loading', listener) this Registers a listener for the did-stop-loading event.
on('dom-ready', listener) this Registers a listener for the dom-ready event.
on('enter-html-full-screen', listener) this Registers a listener for the enter-html-full-screen event.
on('focus', listener) this Registers a listener for the focus event.
on('found-in-page', listener) this Registers a listener for the found-in-page event.
on('frame-created', listener) this Registers a listener for the frame-created event.
on('ipc-message', listener) this Registers a listener for the ipc-message event.
on('ipc-message-sync', listener) this Registers a listener for the ipc-message-sync event.
on('leave-html-full-screen', listener) this Registers a listener for the leave-html-full-screen event.
on('login', listener) this Registers a listener for the login event.
on('media-paused', listener) this Registers a listener for the media-paused event.
on('media-started-playing', listener) this Registers a listener for the media-started-playing event.
on('new-window', listener) this Registers a listener for the new-window event.
on('page-favicon-updated', listener) this Registers a listener for the page-favicon-updated event.
on('page-title-updated', listener) this Registers a listener for the page-title-updated event.
on('paint', listener) this Registers a listener for the paint event.
on('plugin-crashed', listener) this Registers a listener for the plugin-crashed event.
on('preferred-size-changed', listener) this Registers a listener for the preferred-size-changed event.
on('preload-error', listener) this Registers a listener for the preload-error event.
on('render-process-gone', listener) this Registers a listener for the render-process-gone event.
on('responsive', listener) this Registers a listener for the responsive event.
on('select-bluetooth-device', listener) this Registers a listener for the select-bluetooth-device event.
on('select-client-certificate', listener) this Registers a listener for the select-client-certificate event.
on('unresponsive', listener) this Registers a listener for the unresponsive event.
on('update-target-url', listener) this Registers a listener for the update-target-url event.
on('will-attach-webview', listener) this Registers a listener for the will-attach-webview event.
on('will-navigate', listener) this Registers a listener for the will-navigate event.
on('will-prevent-unload', listener) this Registers a listener for the will-prevent-unload event.
on('will-redirect', listener) this Registers a listener for the will-redirect event.
on('zoom-changed', listener) this Registers a listener for the zoom-changed event.
once(event, listener) this Registers a one-time listener for the before-input-event event.
once(event, listener) this Registers a one-time listener for the blur event.
once(event, listener) this Registers a one-time listener for the certificate-error event.
once(event, listener) this Registers a one-time listener for the console-message event.
once(event, listener) this Registers a one-time listener for the context-menu event.
once(event, listener) this Registers a one-time listener for the crashed event.
once(event, listener) this Registers a one-time listener for the cursor-changed event.
once(event, listener) this Registers a one-time listener for the destroyed event.
once(event, listener) this Registers a one-time listener for the devtools-closed event.
once(event, listener) this Registers a one-time listener for the devtools-focused event.
once(event, listener) this Registers a one-time listener for the devtools-opened event.
once(event, listener) this Registers a one-time listener for the devtools-reload-page event.
once(event, listener) this Registers a one-time listener for the did-attach-webview event.
once(event, listener) this Registers a one-time listener for the did-change-theme-color event.
once(event, listener) this Registers a one-time listener for the did-create-window event.
once(event, listener) this Registers a one-time listener for the did-fail-load event.
once(event, listener) this Registers a one-time listener for the did-fail-provisional-load event.
once(event, listener) this Registers a one-time listener for the did-finish-load event.
once(event, listener) this Registers a one-time listener for the did-frame-finish-load event.
once(event, listener) this Registers a one-time listener for the did-frame-navigate event.
once(event, listener) this Registers a one-time listener for the did-navigate event.
once(event, listener) this Registers a one-time listener for the did-navigate-in-page event.
once(event, listener) this Registers a one-time listener for the did-redirect-navigation event.
once(event, listener) this Registers a one-time listener for the did-start-loading event.
once(event, listener) this Registers a one-time listener for the did-start-navigation event.
once(event, listener) this Registers a one-time listener for the did-stop-loading event.
once(event, listener) this Registers a one-time listener for the dom-ready event.
once(event, listener) this Registers a one-time listener for the enter-html-full-screen event.
once(event, listener) this Registers a one-time listener for the focus event.
once(event, listener) this Registers a one-time listener for the found-in-page event.
once(event, listener) this Registers a one-time listener for the frame-created event.
once(event, listener) this Registers a one-time listener for the ipc-message event.
once(event, listener) this Registers a one-time listener for the ipc-message-sync event.
once(event, listener) this Registers a one-time listener for the leave-html-full-screen event.
once(event, listener) this Registers a one-time listener for the login event.
once(event, listener) this Registers a one-time listener for the media-paused event.
once(event, listener) this Registers a one-time listener for the media-started-playing event.
once(event, listener) this Registers a one-time listener for the new-window event.
once(event, listener) this Registers a one-time listener for the page-favicon-updated event.
once(event, listener) this Registers a one-time listener for the page-title-updated event.
once(event, listener) this Registers a one-time listener for the paint event.
once(event, listener) this Registers a one-time listener for the plugin-crashed event.
once(event, listener) this Registers a one-time listener for the preferred-size-changed event.
once(event, listener) this Registers a one-time listener for the preload-error event.
once(event, listener) this Registers a one-time listener for the render-process-gone event.
once(event, listener) this Registers a one-time listener for the responsive event.
once(event, listener) this Registers a one-time listener for the select-bluetooth-device event.
once(event, listener) this Registers a one-time listener for the select-client-certificate event.
once(event, listener) this Registers a one-time listener for the unresponsive event.
once(event, listener) this Registers a one-time listener for the update-target-url event.
once(event, listener) this Registers a one-time listener for the will-attach-webview event.
once(event, listener) this Registers a one-time listener for the will-navigate event.
once(event, listener) this Registers a one-time listener for the will-prevent-unload event.
once(event, listener) this Registers a one-time listener for the will-redirect event.
once(event, listener) this Registers a one-time listener for the zoom-changed event.
openDevTools(options?) void Opens the developer tools.
paste() void Executes the editing command paste in the web page.
pasteAndMatchStyle() void Executes the editing command pasteAndMatchStyle in the web page.
postMessage(channel, message, transfer?) void Sends a message to the renderer process, optionally transferring ownership of message ports.
print(options?, callback?) void Prints the window's web page.
printToPDF(options) Promise<Buffer> Prints the window's web page as PDF.
redo() void Executes the editing command redo in the web page.
reload() void Reloads the current web page.
reloadIgnoringCache() void Reloads the current page and ignores the cache.
removeInsertedCSS(key) Promise<void> Removes the inserted CSS from the current web page identified by its key.
removeListener(event, listener) this Removes a previously registered before-input-event event listener.
removeListener(event, listener) this Removes a previously registered blur event listener.
removeListener(event, listener) this Removes a previously registered certificate-error event listener.
removeListener(event, listener) this Removes a previously registered console-message event listener.
removeListener(event, listener) this Removes a previously registered context-menu event listener.
removeListener(event, listener) this Removes a previously registered crashed event listener.
removeListener(event, listener) this Removes a previously registered cursor-changed event listener.
removeListener(event, listener) this Removes a previously registered destroyed event listener.
removeListener(event, listener) this Removes a previously registered devtools-closed event listener.
removeListener(event, listener) this Removes a previously registered devtools-focused event listener.
removeListener(event, listener) this Removes a previously registered devtools-opened event listener.
removeListener(event, listener) this Removes a previously registered devtools-reload-page event listener.
removeListener(event, listener) this Removes a previously registered did-attach-webview event listener.
removeListener(event, listener) this Removes a previously registered did-change-theme-color event listener.
removeListener(event, listener) this Removes a previously registered did-create-window event listener.
removeListener(event, listener) this Removes a previously registered did-fail-load event listener.
removeListener(event, listener) this Removes a previously registered did-fail-provisional-load event listener.
removeListener(event, listener) this Removes a previously registered did-finish-load event listener.
removeListener(event, listener) this Removes a previously registered did-frame-finish-load event listener.
removeListener(event, listener) this Removes a previously registered did-frame-navigate event listener.
removeListener(event, listener) this Removes a previously registered did-navigate event listener.
removeListener(event, listener) this Removes a previously registered did-navigate-in-page event listener.
removeListener(event, listener) this Removes a previously registered did-redirect-navigation event listener.
removeListener(event, listener) this Removes a previously registered did-start-loading event listener.
removeListener(event, listener) this Removes a previously registered did-start-navigation event listener.
removeListener(event, listener) this Removes a previously registered did-stop-loading event listener.
removeListener(event, listener) this Removes a previously registered dom-ready event listener.
removeListener(event, listener) this Removes a previously registered enter-html-full-screen event listener.
removeListener(event, listener) this Removes a previously registered focus event listener.
removeListener(event, listener) this Removes a previously registered found-in-page event listener.
removeListener(event, listener) this Removes a previously registered frame-created event listener.
removeListener(event, listener) this Removes a previously registered ipc-message event listener.
removeListener(event, listener) this Removes a previously registered ipc-message-sync event listener.
removeListener(event, listener) this Removes a previously registered leave-html-full-screen event listener.
removeListener(event, listener) this Removes a previously registered login event listener.
removeListener(event, listener) this Removes a previously registered media-paused event listener.
removeListener(event, listener) this Removes a previously registered media-started-playing event listener.
removeListener(event, listener) this Removes a previously registered new-window event listener.
removeListener(event, listener) this Removes a previously registered page-favicon-updated event listener.
removeListener(event, listener) this Removes a previously registered page-title-updated event listener.
removeListener(event, listener) this Removes a previously registered paint event listener.
removeListener(event, listener) this Removes a previously registered plugin-crashed event listener.
removeListener(event, listener) this Removes a previously registered preferred-size-changed event listener.
removeListener(event, listener) this Removes a previously registered preload-error event listener.
removeListener(event, listener) this Removes a previously registered render-process-gone event listener.
removeListener(event, listener) this Removes a previously registered responsive event listener.
removeListener(event, listener) this Removes a previously registered select-bluetooth-device event listener.
removeListener(event, listener) this Removes a previously registered select-client-certificate event listener.
removeListener(event, listener) this Removes a previously registered unresponsive event listener.
removeListener(event, listener) this Removes a previously registered update-target-url event listener.
removeListener(event, listener) this Removes a previously registered will-attach-webview event listener.
removeListener(event, listener) this Removes a previously registered will-navigate event listener.
removeListener(event, listener) this Removes a previously registered will-prevent-unload event listener.
removeListener(event, listener) this Removes a previously registered will-redirect event listener.
removeListener(event, listener) this Removes a previously registered zoom-changed event listener.
removeWorkSpace(path) void Removes the specified path from the DevTools workspace.
replace(text) void Executes the editing command replace in the web page.
replaceMisspelling(text) void Executes the editing command replaceMisspelling in the web page.
savePage(fullPath, saveType) Promise<void> Saves the current web page to the given path.
selectAll() void Executes the editing command selectAll in the web page.
send(channel, args?) void Sends an asynchronous message to the renderer process via channel, along with arguments.
sendInputEvent(inputEvent) void Injects a trusted input event into the page, driving the same input pipeline a real user produces (unlike untrusted dispatchEvent, which CodeMirror and the CSS :hover engine ignore).
sendToFrame(frameId, channel, args?) void Sends an asynchronous message to a specific frame in a renderer process via channel.
setAudioMuted(muted) void Mutes or unmutes the audio on the current web page.
setBackgroundThrottling(allowed) void Controls whether this web contents throttles animations and timers when backgrounded.
setDevToolsWebContents(devToolsWebContents) void Uses the given web contents as the target to show DevTools.
setFrameRate(fps) void Sets the frame rate when offscreen rendering is enabled. Only values between 1 and 240 are accepted.
setIgnoreMenuShortcuts(ignore) void Ignores application menu shortcuts while this web contents is focused.
setImageAnimationPolicy(policy) void Sets the image animation policy for this web contents.
setUserAgent(userAgent) void Overrides the user agent for this web page.
setVisualZoomLevelLimits(minimumLevel, maximumLevel) Promise<void> Sets the maximum and minimum pinch-to-zoom level.
setWebRTCIPHandlingPolicy(policy) void Sets the WebRTC IP handling policy.
setWindowOpenHandler(handler) void Sets a handler called before a new window is requested by the renderer.
setZoomFactor(factor) void Changes the zoom factor to the specified factor.
setZoomLevel(level) void Changes the zoom level to the specified level.
showDefinitionForSelection() void Shows a pop-up dictionary that searches the selected word on the page. Only available on macOS.
startDrag(item) void Sets the item as the dragging item for the current drag-drop operation.
startPainting() void Starts painting when offscreen rendering is enabled and not painting.
stop() void Stops any pending navigation.
stopFindInPage(action) void Stops any findInPage request for the web contents with the provided action.
stopPainting() void Stops painting when offscreen rendering is enabled and painting.
takeHeapSnapshot(filePath) Promise<void> Takes a V8 heap snapshot and saves it to filePath.
toggleDevTools() void Toggles the developer tools.
undo() void Executes the editing command undo in the web page.
unselect() void Executes the editing command unselect in the web page.

Links to this page: