webFrameMain

    Process: Main

    The webFrameMain module can be used to lookup frames across existing instances. Navigation events are the common use case.

    You can also access frames of existing pages by using the mainFrame property of WebContents.

    These methods can be accessed from the webFrameMain module:

    • processId Integer - An Integer representing the internal ID of the process which owns the frame.

    Returns WebFrameMain | undefined - A frame with the given process and routing IDs, or undefined if there is no WebFrameMain associated with the given IDs.

    Class: WebFrameMain

    Process: Main
    This class is not exported from the 'electron' module. It is only available as a return value of other methods in the Electron API.

    Event: ‘dom-ready’

    Emitted when the document is loaded.

    frame.executeJavaScript(code[, userGesture])

    • code string
    • userGesture boolean (optional) - Default is .

    Returns Promise<unknown> - A promise that resolves with the result of the executed code or is rejected if execution throws or results in a rejected promise.

    Evaluates code in page.

    In the browser window some HTML APIs like requestFullScreen can only be invoked by a gesture from the user. Setting userGesture to true will remove this limitation.

    frame.reload()

    frame.send(channel, ...args)

    • channel string
    • ...args any[]

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

    The renderer process can handle the message by listening to channel with the module.

    frame.postMessage(channel, message, [transfer])

    • channel string
    • message any
    • transfer MessagePortMain[] (optional)

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

    The transferred MessagePortMain objects will be available in the renderer process by accessing the ports property of the emitted event. When they arrive in the renderer, they will be native DOM MessagePort objects.

    For example:

    frame.ipc Readonly

    An IpcMain instance scoped to the frame.

    IPC messages sent with ipcRenderer.send, ipcRenderer.sendSync or ipcRenderer.postMessage will be delivered in the following order:

    1. contents.on('ipc-message')
    2. contents.mainFrame.on(channel)
    3. contents.ipc.on(channel)
    4. ipcMain.on(channel)

    Handlers registered with invoke will be checked in the following order. The first one that is defined will be called, the rest will be ignored.

    1. contents.mainFrame.handle(channel)
    2. ipcMain.handle(channel)

    In most cases, only the main frame of a WebContents can send or receive IPC messages. However, if the nodeIntegrationInSubFrames option is enabled, it is possible for child frames to send and receive IPC messages also. The interface may be more convenient when nodeIntegrationInSubFrames is not enabled.

    frame.url Readonly

    A representing the current URL of the frame.

    frame.origin Readonly

    frame.top Readonly

    A WebFrameMain | null representing top frame in the frame hierarchy to which frame belongs.

    frame.parent Readonly

    A WebFrameMain | null representing parent frame of frame, the property would be null if frame is the top frame in the frame hierarchy.

    frame.frames Readonly

    A WebFrameMain[] collection containing the direct descendents of frame.

    frame.framesInSubtree Readonly

    A WebFrameMain[] collection containing every frame in the subtree of frame, including itself. This can be useful when traversing through all frames.

    frame.frameTreeNodeId Readonly

    An Integer representing the id of the frame’s internal FrameTreeNode instance. This id is browser-global and uniquely identifies a frame that hosts content. The identifier is fixed at the creation of the frame and stays constant for the lifetime of the frame. When the frame is removed, the id is not used again.

    frame.name Readonly

    A string representing the frame name.

    frame.osProcessId Readonly

    An Integer representing the operating system pid of the process which owns this frame.

    frame.processId Readonly

    An Integer representing the Chromium internal pid of the process which owns this frame. This is not the same as the OS process ID; to read that use frame.osProcessId.

    frame.routingId Readonly

    An Integer representing the unique frame id in the current renderer process. Distinct WebFrameMain instances that refer to the same underlying frame will have the same routingId.

    Readonly

    A string representing the visibility state of the frame.