WebContents

external class WebContents : EventEmitter(source)

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
external object Companion

Properties

Link copied to clipboard
external var audioMuted: Boolean

A boolean property that determines whether this page is muted.

Link copied to clipboard

A boolean property that determines whether or not this WebContents will throttle animations and timers when the page becomes backgrounded. This also affects the Page Visibility API.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
external val debugger: Debugger

A Debugger instance for this webContents.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

A WebContents | null property that represents the DevTools WebContents associated with a given WebContents.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
external val focusedFrame: WebFrameMain?

A WebFrameMain | null property that represents the currently focused frame in this WebContents. Can be the top frame, an inner <iframe>, or null if nothing is focused.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
external var frameRate: Double

An Integer property that sets the frame rate of the web contents to the specified number. Only values between 1 and 240 are accepted.

Link copied to clipboard

A WebContents | null property that represents a WebContents instance that might own this WebContents.

Link copied to clipboard
external val id: Double

A Integer representing the unique ID of this WebContents. Each ID is unique among all WebContents instances of the entire Electron application.

Link copied to clipboard
Link copied to clipboard
external val ipc: IpcMain

An IpcMain scoped to just IPC messages sent from this WebContents.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
external val mainFrame: WebFrameMain

A WebFrameMain property that represents the top frame of the page's frame hierarchy.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

A NavigationHistory used by this webContents.

Link copied to clipboard
external val opener: WebFrameMain?

A WebFrameMain | null property that represents the frame that opened this WebContents, either with open(), or by navigating a link with a target attribute.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
external val session: Session

A Session used by this webContents.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
external var userAgent: String

A string property that determines the user agent for this web page.

Link copied to clipboard
Link copied to clipboard
external var zoomFactor: Double

A number property that determines the zoom factor for this web contents.

Link copied to clipboard
external var zoomLevel: Double

A number property that determines the zoom level for this web contents.

Functions

Link copied to clipboard
external fun addListener(type: EventType, listener: EventListener)
Link copied to clipboard
external fun addWorkSpace(path: String)

Adds the specified path to DevTools workspace. Must be used after DevTools creation:

Link copied to clipboard

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.

Link copied to clipboard
external fun beginFrameSubscription(callback: (image: NativeImage, dirtyRect: Rectangle) -> Unit)
external fun beginFrameSubscription(onlyDirty: Boolean, callback: (image: NativeImage, dirtyRect: Rectangle) -> Unit)

Begin subscribing for presentation events and captured frames, the callback will be called with callback(image, dirtyRect) when there is a presentation event.

Link copied to clipboard
external fun canGoBack(): Boolean

Whether the browser can go back to previous web page.

Link copied to clipboard
external fun canGoForward(): Boolean

Whether the browser can go forward to next web page.

Link copied to clipboard
external fun canGoToOffset(offset: Double): Boolean

Whether the web page can go to offset.

Link copied to clipboard
external fun capturePage(rect: Rectangle = definedExternally, opts: Opts = definedExternally): Promise<NativeImage>

Resolves with a NativeImage

Link copied to clipboard
external fun centerSelection()

Centers the current text selection in web page.

Link copied to clipboard
external fun clearHistory()

Clears the navigation history.

Link copied to clipboard
external fun close(opts: CloseOpts = definedExternally)

Closes the page, as if the web content had called window.close().

Link copied to clipboard
external fun closeDevTools()

Closes the DevTools view.

Link copied to clipboard
external fun copy()

Executes the editing command copy in web page.

Link copied to clipboard
external fun copyImageAt(x: Double, y: Double)

Copy the image at the given position to the clipboard.

Link copied to clipboard
external fun cut()

Executes the editing command cut in web page.

Link copied to clipboard
external fun delete()

Executes the editing command delete in web page.

Link copied to clipboard
external fun disableDeviceEmulation()

Disable device emulation enabled by webContents.enableDeviceEmulation.

Link copied to clipboard
external fun downloadURL(url: String, options: DownloadURLOptions = definedExternally)

Initiates a download of the resource at url without navigating. The will-download event of session will be triggered.

Link copied to clipboard
external fun emit(type: EventType, vararg args: Any?): Boolean
Link copied to clipboard
external fun enableDeviceEmulation(parameters: Parameters)

Enable device emulation with the given parameters.

Link copied to clipboard
external fun endFrameSubscription()

End subscribing for frame presentation events.

Link copied to clipboard
Link copied to clipboard
external fun executeJavaScript(code: String, userGesture: Boolean = definedExternally): Promise<Any?>

A promise that resolves with the result of the executed code or is rejected if the result of the code is a rejected promise.

Link copied to clipboard
external fun executeJavaScriptInIsolatedWorld(worldId: Double, scripts: ReadonlyArray<WebSource>, userGesture: Boolean = definedExternally): Promise<Any?>

A promise that resolves with the result of the executed code or is rejected if the result of the code is a rejected promise.

Link copied to clipboard
external fun findInPage(text: String, options: FindInPageOptions = definedExternally): Double

The request id used for the request.

Link copied to clipboard
external fun focus()

Focuses the web page.

Link copied to clipboard

Forcefully terminates the renderer process that is currently hosting this webContents. This will cause the render-process-gone event to be emitted with the reason=killed || reason=crashed. Please note that some webContents share renderer processes and therefore calling this method may also crash the host process for other webContents as well.

Link copied to clipboard

Information about all Shared Workers.

Link copied to clipboard

whether or not this WebContents will throttle animations and timers when the page becomes backgrounded. This also affects the Page Visibility API.

Link copied to clipboard
external fun getDevToolsTitle(): String

the current title of the DevTools window. This will only be visible if DevTools is opened in undocked or detach mode.

Link copied to clipboard
external fun getFrameRate(): Double

If offscreen rendering is enabled returns the current frame rate.

Link copied to clipboard
external fun getMaxListeners(): Double
Link copied to clipboard
external fun getMediaSourceId(requestWebContents: WebContents): String

The identifier of a WebContents stream. This identifier can be used with navigator.mediaDevices.getUserMedia using a chromeMediaSource of tab. The identifier is restricted to the web contents that it is registered to and is only valid for 10 seconds.

Link copied to clipboard

The Chrome DevTools Protocol TargetID associated with this WebContents. This is the reverse of webContents.fromDevToolsTargetId().

Link copied to clipboard
external fun getOSProcessId(): Double

The operating system pid of the associated renderer process.

Link copied to clipboard

Get the system printer list.

Link copied to clipboard
external fun getProcessId(): Double

The Chromium internal pid of the associated renderer. Can be compared to the frameProcessId passed by frame specific navigation events (e.g. did-frame-navigate)

Link copied to clipboard
external fun getTitle(): String

The title of the current web page.

Link copied to clipboard

the type of the webContent. Can be backgroundPage, window, browserView, remote, webview or offscreen.

Link copied to clipboard
external fun getURL(): String

The URL of the current web page.

Link copied to clipboard
external fun getUserAgent(): String

The user agent for this web page.

Link copied to clipboard

Returns the WebRTC IP Handling Policy.

Link copied to clipboard

By default this value is { min: 0, max: 0 } , which would apply no restriction on the udp port range.

Link copied to clipboard
external fun getZoomFactor(): Double

the current zoom factor.

Link copied to clipboard
external fun getZoomLevel(): Double

the current zoom level.

Link copied to clipboard
external fun goBack()

Makes the browser go back a web page.

Link copied to clipboard
external fun goForward()

Makes the browser go forward a web page.

Link copied to clipboard
external fun goToIndex(index: Double)

Navigates browser to the specified absolute web page index.

Link copied to clipboard
external fun goToOffset(offset: Double)

Navigates to the specified offset from the "current entry".

Link copied to clipboard
external fun insertCSS(css: String, options: InsertCSSOptions = definedExternally): Promise<String>

A promise that resolves with a key for the inserted CSS that can later be used to remove the CSS via contents.removeInsertedCSS(key).

Link copied to clipboard
external fun insertText(text: String): Promise<Void>

Inserts text to the focused element.

Link copied to clipboard
external fun inspectElement(x: Double, y: Double)

Starts inspecting element at position (x, y).

Link copied to clipboard
external fun inspectServiceWorker()

Opens the developer tools for the service worker context.

Link copied to clipboard
external fun inspectSharedWorker()

Opens the developer tools for the shared worker context.

Link copied to clipboard
external fun inspectSharedWorkerById(workerId: String)

Inspects the shared worker based on its ID.

Link copied to clipboard
external fun invalidate()

Schedules a full repaint of the window this web contents is in.

Link copied to clipboard
external fun isAudioMuted(): Boolean

Whether this page has been muted.

Link copied to clipboard
external fun isBeingCaptured(): Boolean

Whether this page is being captured. It returns true when the capturer count is greater than 0.

Link copied to clipboard
external fun isCrashed(): Boolean

Whether the renderer process has crashed.

Link copied to clipboard
external fun isCurrentlyAudible(): Boolean

Whether audio is currently playing.

Link copied to clipboard
external fun isDestroyed(): Boolean

Whether the web page is destroyed.

Link copied to clipboard
external fun isDevToolsFocused(): Boolean

Whether the DevTools view is focused .

Link copied to clipboard
external fun isDevToolsOpened(): Boolean

Whether the DevTools view is opened.

Link copied to clipboard
external fun isFocused(): Boolean

Whether the web page is focused.

Link copied to clipboard
external fun isLoading(): Boolean

Whether web page is still loading resources.

Link copied to clipboard
external fun isLoadingMainFrame(): Boolean

Whether the main frame (and not just iframes or frames within it) is still loading.

Link copied to clipboard
external fun isOffscreen(): Boolean

Indicates whether offscreen rendering is enabled.

Link copied to clipboard
external fun isPainting(): Boolean

If offscreen rendering is enabled returns whether it is currently painting.

Link copied to clipboard

Whether the web page is waiting for a first-response from the main resource of the page.

Link copied to clipboard
external fun listenerCount(type: EventType, listener: EventListener): Double
Link copied to clipboard
Link copied to clipboard
external fun loadFile(filePath: String, options: LoadFileOptions = definedExternally): Promise<Void>

the promise will resolve when the page has finished loading (see did-finish-load), and rejects if the page fails to load (see did-fail-load).

Link copied to clipboard
external fun loadURL(url: String, options: LoadURLOptions = definedExternally): Promise<Void>

the promise will resolve when the page has finished loading (see did-finish-load), and rejects if the page fails to load (see did-fail-load). A noop rejection handler is already attached, which avoids unhandled rejection errors. If the existing page has a beforeUnload handler, did-fail-load will be called unless will-prevent-unload is handled.

Link copied to clipboard
external fun off(type: EventType, listener: EventListener)
Link copied to clipboard
external fun on(type: EventType, listener: EventListener)
Link copied to clipboard
external fun once(type: EventType, listener: EventListener)
Link copied to clipboard
external fun openDevTools(options: OpenDevToolsOptions = definedExternally)

Opens the DevTools.

Link copied to clipboard
external fun paste()

Executes the editing command paste in web page.

Link copied to clipboard
external fun pasteAndMatchStyle()

Executes the editing command pasteAndMatchStyle in web page.

Link copied to clipboard
external fun postMessage(channel: String, message: Any?, transfer: ReadonlyArray<MessagePortMain> = definedExternally)

Send a message to the renderer process, optionally transferring ownership of zero or more MessagePortMain objects.

Link copied to clipboard
external fun prependListener(type: EventType, listener: EventListener)
Link copied to clipboard
external fun prependOnceListener(type: EventType, listener: EventListener)
Link copied to clipboard
external fun print(options: WebContentsPrintOptions = definedExternally, callback: (success: Boolean, failureReason: String) -> Unit = definedExternally)

When a custom pageSize is passed, Chromium attempts to validate platform specific minimum values for width_microns and height_microns. Width and height must both be minimum 353 microns but may be higher on some operating systems. If a valid pageSize is not passed and usePrinterDefaultPageSize is false, an error will be thrown.

Link copied to clipboard
external fun printToPDF(options: PrintToPDFOptions): Promise<Buffer<*>>

Resolves with the generated PDF data.

Link copied to clipboard
Link copied to clipboard
external fun redo()

Executes the editing command redo in web page.

Link copied to clipboard
external fun reload()

Reloads the current web page.

Link copied to clipboard
external fun reloadIgnoringCache()

Reloads current page and ignores cache.

Link copied to clipboard
external fun removeAllListeners(type: EventType)
Link copied to clipboard
external fun removeInsertedCSS(key: String): Promise<Void>

Resolves if the removal was successful.

Link copied to clipboard
external fun removeListener(type: EventType, listener: EventListener)
Link copied to clipboard
external fun removeWorkSpace(path: String)

Removes the specified path from DevTools workspace.

Link copied to clipboard
external fun replace(text: String)

Executes the editing command replace in web page.

Link copied to clipboard
external fun replaceMisspelling(text: String)

Executes the editing command replaceMisspelling in web page.

Link copied to clipboard
external fun savePage(fullPath: String, saveType: WebContentsSavePageSaveType): Promise<Void>

resolves if the page is saved.

Link copied to clipboard
external fun scrollToBottom()

Scrolls to the bottom of the current webContents.

Link copied to clipboard
external fun scrollToTop()

Scrolls to the top of the current webContents.

Link copied to clipboard
external fun selectAll()

Executes the editing command selectAll in web page.

Link copied to clipboard
external fun send(channel: String, vararg args: Any?)

Send an asynchronous message to the renderer process via channel, along with arguments. Arguments will be serialized with the Structured Clone Algorithm, just like postMessage, so prototype chains will not be included. Sending Functions, Promises, Symbols, WeakMaps, or WeakSets will throw an exception.

Link copied to clipboard
external fun sendInputEvent(inputEvent: KeyboardInputEvent)
external fun sendInputEvent(inputEvent: MouseInputEvent)
external fun sendInputEvent(inputEvent: MouseWheelInputEvent)

Sends an input event to the page.

Link copied to clipboard
external fun sendToFrame(frameId: Tuple2<Double, Double>, channel: String, vararg args: Any?)
external fun sendToFrame(frameId: Double, channel: String, vararg args: Any?)

Send an asynchronous message to a specific frame in a renderer process via channel, along with arguments. Arguments will be serialized with the Structured Clone Algorithm, just like postMessage, so prototype chains will not be included. Sending Functions, Promises, Symbols, WeakMaps, or WeakSets will throw an exception.

Link copied to clipboard
external fun setAudioMuted(muted: Boolean)

Mute the audio on the current web page.

Link copied to clipboard
external fun setBackgroundThrottling(allowed: Boolean)

Controls whether or not this WebContents will throttle animations and timers when the page becomes backgrounded. This also affects the Page Visibility API.

Link copied to clipboard
external fun setDevToolsTitle(title: String)

Changes the title of the DevTools window to title. This will only be visible if DevTools is opened in undocked or detach mode.

Link copied to clipboard
external fun setDevToolsWebContents(devToolsWebContents: WebContents)

Uses the devToolsWebContents as the target WebContents to show DevTools.

Link copied to clipboard
external fun setFrameRate(fps: Double)

If offscreen rendering is enabled sets the frame rate to the specified number. When webPreferences.offscreen.useSharedTexture is false only values between 1 and 240 are accepted.

Link copied to clipboard
external fun setIgnoreMenuShortcuts(ignore: Boolean)

Ignore application menu shortcuts while this web contents is focused.

Link copied to clipboard

Sets the image animation policy for this webContents. The policy only affects new images, existing images that are currently being animated are unaffected. This is a known limitation in Chromium, you can force image animation to be recalculated with img.src = img.src which will result in no network traffic but will update the animation policy.

Link copied to clipboard
external fun setMaxListeners(n: Number)
Link copied to clipboard
external fun setUserAgent(userAgent: String)

Overrides the user agent for this web page.

Link copied to clipboard
external fun setVisualZoomLevelLimits(minimumLevel: Double, maximumLevel: Double): Promise<Void>

Sets the maximum and minimum pinch-to-zoom level.

Link copied to clipboard

Setting the WebRTC IP handling policy allows you to control which IPs are exposed via WebRTC. See BrowserLeaks for more details.

Link copied to clipboard
external fun setWebRTCUDPPortRange(udpPortRange: UdpPortRange)

Setting the WebRTC UDP Port Range allows you to restrict the udp port range used by WebRTC. By default the port range is unrestricted.

Link copied to clipboard

Called before creating a window when a new window is requested by the renderer, e.g. by window.open(), a link with target="_blank", shift+clicking on a link, or submitting a form with <form target="_blank">. See window.open() for more details and how to use this in conjunction with did-create-window.

Link copied to clipboard
external fun setZoomFactor(factor: Double)

Changes the zoom factor to the specified factor. Zoom factor is zoom percent divided by 100, so 300% = 3.0.

Link copied to clipboard
external fun setZoomLevel(level: Double)

Changes the zoom level to the specified level. The original size is 0 and each increment above or below represents zooming 20% larger or smaller to default limits of 300% and 50% of original size, respectively. The formula for this is scale := 1.2 ^ level.

Link copied to clipboard

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

Link copied to clipboard
external fun startDrag(item: Item)

Sets the item as dragging item for current drag-drop operation, file is the absolute path of the file to be dragged, and icon is the image showing under the cursor when dragging.

Link copied to clipboard
external fun startPainting()

If offscreen rendering is enabled and not painting, start painting.

Link copied to clipboard
external fun stop()

Stops any pending navigation.

Link copied to clipboard

Stops any findInPage request for the webContents with the provided action.

Link copied to clipboard
external fun stopPainting()

If offscreen rendering is enabled and painting, stop painting.

Link copied to clipboard
external fun takeHeapSnapshot(filePath: String): Promise<Void>

Indicates whether the snapshot has been created successfully.

Link copied to clipboard
external fun toggleDevTools()

Toggles the developer tools.

Link copied to clipboard
external fun undo()

Executes the editing command undo in web page.

Link copied to clipboard
external fun unselect()

Executes the editing command unselect in web page.