WebContents

external class WebContents : EventEmitter(source)

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

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

A Debugger instance for this webContents.

Link copied to clipboard
Link copied to clipboard

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

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

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 instance that might own this WebContents.

Link copied to clipboard
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

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

Link copied to clipboard
Link copied to clipboard

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

Link copied to clipboard
Link copied to clipboard

A NavigationHistory used by this webContents.

Link copied to clipboard

A WebFrameMain 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

A Session used by this webContents.

Link copied to clipboard
Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard

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

Functions

Link copied to clipboard
fun addListener(type: EventType, listener: EventListener)
Link copied to clipboard
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
fun beginFrameSubscription(callback: (image: NativeImage, dirtyRect: Rectangle) -> Unit)
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

Whether the browser can go back to previous web page.

Link copied to clipboard

Whether the browser can go forward to next web page.

Link copied to clipboard

Whether the web page can go to offset.

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

Resolves with a NativeImage

Link copied to clipboard

Centers the current text selection in web page.

Link copied to clipboard

Clears the navigation history.

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

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

Link copied to clipboard

Closes the devtools.

Link copied to clipboard
fun copy()

Executes the editing command copy in web page.

Link copied to clipboard

Copy the image at the given position to the clipboard.

Link copied to clipboard
fun cut()

Executes the editing command cut in web page.

Link copied to clipboard
fun delete()

Executes the editing command delete in web page.

Link copied to clipboard

Disable device emulation enabled by webContents.enableDeviceEmulation.

Link copied to clipboard
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
fun emit(type: EventType, vararg args: Any?): Boolean
Link copied to clipboard

Enable device emulation with the given parameters.

Link copied to clipboard

End subscribing for frame presentation events.

Link copied to clipboard
Link copied to clipboard
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
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
fun findInPage(text: String, options: FindInPageOptions = definedExternally): Double

The request id used for the request.

Link copied to clipboard
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

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

If offscreen rendering is enabled returns the current frame rate.

Link copied to clipboard
Link copied to clipboard
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 operating system pid of the associated renderer process.

Link copied to clipboard

Get the system printer list.

Link copied to clipboard

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

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
fun getURL(): String

The URL of the current web page.

Link copied to clipboard

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

the current zoom factor.

Link copied to clipboard

the current zoom level.

Link copied to clipboard
fun goBack()

Makes the browser go back a web page.

Link copied to clipboard
fun goForward()

Makes the browser go forward a web page.

Link copied to clipboard
fun goToIndex(index: Double)

Navigates browser to the specified absolute web page index.

Link copied to clipboard
fun goToOffset(offset: Double)

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

Link copied to clipboard
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

Inserts text to the focused element.

Link copied to clipboard

Starts inspecting element at position (x, y).

Link copied to clipboard

Opens the developer tools for the service worker context.

Link copied to clipboard

Opens the developer tools for the shared worker context.

Link copied to clipboard

Inspects the shared worker based on its ID.

Link copied to clipboard

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

Link copied to clipboard

Whether this page has been muted.

Link copied to clipboard

Whether this page is being captured. It returns true when the capturer count is large then 0.

Link copied to clipboard

Whether the renderer process has crashed.

Link copied to clipboard

Whether audio is currently playing.

Link copied to clipboard

Whether the web page is destroyed.

Link copied to clipboard

Whether the devtools view is focused .

Link copied to clipboard

Whether the devtools is opened.

Link copied to clipboard

Whether the web page is focused.

Link copied to clipboard

Whether web page is still loading resources.

Link copied to clipboard

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

Link copied to clipboard

Indicates whether offscreen rendering is enabled.

Link copied to clipboard

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
Link copied to clipboard
Link copied to clipboard
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
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.

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

Opens the devtools.

Link copied to clipboard
fun paste()

Executes the editing command paste in web page.

Link copied to clipboard

Executes the editing command pasteAndMatchStyle in web page.

Link copied to clipboard
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
Link copied to clipboard
Link copied to clipboard
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.

Link copied to clipboard

Resolves with the generated PDF data.

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

Executes the editing command redo in web page.

Link copied to clipboard
fun reload()

Reloads the current web page.

Link copied to clipboard

Reloads current page and ignores cache.

Link copied to clipboard
Link copied to clipboard

Resolves if the removal was successful.

Link copied to clipboard
fun removeListener(type: EventType, listener: EventListener)
Link copied to clipboard

Removes the specified path from DevTools workspace.

Link copied to clipboard
fun replace(text: String)

Executes the editing command replace in web page.

Link copied to clipboard

Executes the editing command replaceMisspelling in web page.

Link copied to clipboard

resolves if the page is saved.

Link copied to clipboard

Scrolls to the bottom of the current webContents.

Link copied to clipboard

Scrolls to the top of the current webContents.

Link copied to clipboard
fun selectAll()

Executes the editing command selectAll in web page.

Link copied to clipboard
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

Sends an input event to the page. Note: The BrowserWindow containing the contents needs to be focused for sendInputEvent() to work.

Link copied to clipboard
fun sendToFrame(frameId: JsTuple2<Double, Double>, channel: String, vararg args: Any?)
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

Mute the audio on the current web page.

Link copied to clipboard

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

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
fun setDevToolsWebContents(devToolsWebContents: WebContents)

Uses the devToolsWebContents as the target WebContents to show devtools.

Link copied to clipboard

If offscreen rendering is enabled sets the frame rate to the specified number. Only values between 1 and 240 are accepted.

Link copied to clipboard

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
Link copied to clipboard
fun setUserAgent(userAgent: String)

Overrides the user agent for this web page.

Link copied to clipboard
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

Setting the WebRTC UDP Port Range allows you to restrict the udp port range used by WebRTC. By default the port range is unrestricted. Note: To reset to an unrestricted port range this value should be set to { min: 0, max: 0 }.

Link copied to clipboard
fun setWindowOpenHandler(handler: (details: HandlerDetails) -> Any)

Called before creating a window 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
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
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
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

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

Link copied to clipboard
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

If offscreen rendering is enabled and painting, stop painting.

Link copied to clipboard

Indicates whether the snapshot has been created successfully.

Link copied to clipboard

Toggles the developer tools.

Link copied to clipboard
fun undo()

Executes the editing command undo in web page.

Link copied to clipboard
fun unselect()

Executes the editing command unselect in web page.