webFrameMain
进程:
The webFrameMain
module can be used to lookup frames across existing WebContents
instances. Navigation events are the common use case.
You can also access frames of existing pages by using the mainFrame
property of .
These methods can be accessed from the webFrameMain
module:
processId
Integer - AnInteger
representing the internal ID of the process which owns the frame.routingId
Integer - AnInteger
representing the unique frame ID in the current renderer process. Routing IDs can be retrieved fromWebFrameMain
instances (frame.routingId
) and are also passed by frame specificWebContents
navigation events (e.g.did-frame-navigate
).
Returns - A frame with the given process and routing IDs, or undefined
if there is no WebFrameMain associated with the given IDs.
进程:主进程
frame.executeJavaScript(code[, userGesture])
code
StringuserGesture
Boolean (optional) - Default isfalse
.
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.
在浏览器窗口中,一些HTML API(如requestFullScreen
)只能是 由来自用户的手势调用。 将 userGesture
设置为 true
将删除此限制。
frame.reload()
Returns boolean
- Whether the reload was initiated successfully. Only results in false
when the frame has no history.
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 [Structured Clone Algorithm][SCA], 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.
channel
Stringtransfer
MessagePortMain[] (optional)
Send a message to the renderer process, optionally transferring ownership of zero or more [MessagePortMain
][] 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.
例如:
A WebFrameMain | null
representing top frame in the frame hierarchy to which frame
belongs.
A WebFrameMain | null
representing parent frame of frame
, the property would be null
if frame
is the top frame in the frame hierarchy.
A WebFrameMain[]
collection containing the direct descendents of frame
.
A WebFrameMain[]
collection containing every frame in the subtree of frame
, including itself. This can be useful when traversing through all frames.
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.
A String
representing the frame name.
An Integer
representing the operating system pid
of the process which owns this frame.
An Integer
representing the unique frame id in the current renderer process. Distinct instances that refer to the same underlying frame will have the same routingId
.