ICoreWebView2Frame2

Undocumented in source.

Members

Functions

ExecuteScript
HRESULT ExecuteScript(LPCWSTR javaScript, ICoreWebView2ExecuteScriptCompletedHandler handler)

Run JavaScript code from the javascript parameter in the current frame. The result of evaluating the provided JavaScript is passed to the completion handler. The result value is a JSON encoded string. If the result is undefined, contains a reference cycle, or otherwise is not able to be encoded into JSON, then the result is considered to be null, which is encoded in JSON as the string "null".

PostWebMessageAsJson
HRESULT PostWebMessageAsJson(LPCWSTR webMessageAsJson)

Posts the specified webMessage to the frame. The frame receives the message by subscribing to the message event of the window.chrome.webview of the frame document.

PostWebMessageAsString
HRESULT PostWebMessageAsString(LPCWSTR webMessageAsString)

Posts a message that is a simple string rather than a JSON string representation of a JavaScript object. This behaves in exactly the same manner as PostWebMessageAsJson, but the data property of the event args of the window.chrome.webview message is a string with the same value as webMessageAsString. Use this instead of PostWebMessageAsJson if you want to communicate using simple strings rather than JSON objects.

add_ContentLoading
HRESULT add_ContentLoading(ICoreWebView2FrameContentLoadingEventHandler eventHandler, EventRegistrationToken* token)

Add an event handler for the ContentLoading event. ContentLoading triggers before any content is loaded, including scripts added with AddScriptToExecuteOnDocumentCreated. ContentLoading does not trigger if a same page navigation occurs (such as through fragment navigations or history.pushState navigations). This operation follows the NavigationStarting and precedes NavigationCompleted events.

add_DOMContentLoaded
HRESULT add_DOMContentLoaded(ICoreWebView2FrameDOMContentLoadedEventHandler eventHandler, EventRegistrationToken* token)

Add an event handler for the DOMContentLoaded event. DOMContentLoaded is raised when the iframe html document has been parsed. This aligns with the document's DOMContentLoaded event in html.

add_NavigationCompleted
HRESULT add_NavigationCompleted(ICoreWebView2FrameNavigationCompletedEventHandler eventHandler, EventRegistrationToken* token)

Add an event handler for the NavigationCompleted event. NavigationCompleted runs when the CoreWebView2Frame has completely loaded (concurrently when body.onload runs) or loading stopped with error.

add_NavigationStarting
HRESULT add_NavigationStarting(ICoreWebView2FrameNavigationStartingEventHandler eventHandler, EventRegistrationToken* token)

Add an event handler for the NavigationStarting event. A frame navigation will raise a NavigationStarting event and a CoreWebView2.FrameNavigationStarting event. All of the FrameNavigationStarting event handlers for the current frame will be run before the NavigationStarting event handlers. All of the event handlers share a common NavigationStartingEventArgs object. Whichever event handler is last to change the NavigationStartingEventArgs.Cancel property will decide if the frame navigation will be cancelled. Redirects raise this event as well, and the navigation id is the same as the original one.

add_WebMessageReceived
HRESULT add_WebMessageReceived(ICoreWebView2FrameWebMessageReceivedEventHandler handler, EventRegistrationToken* token)

Add an event handler for the WebMessageReceived event. WebMessageReceived runs when the ICoreWebView2Settings::IsWebMessageEnabled setting is set and the frame document runs window.chrome.webview.postMessage. The postMessage function is void postMessage(object) where object is any object supported by JSON conversion.

remove_ContentLoading
HRESULT remove_ContentLoading(EventRegistrationToken token)

Remove an event handler previously added with add_ContentLoading.

remove_DOMContentLoaded
HRESULT remove_DOMContentLoaded(EventRegistrationToken token)

Remove an event handler previously added with add_DOMContentLoaded.

remove_NavigationCompleted
HRESULT remove_NavigationCompleted(EventRegistrationToken token)

Remove an event handler previously added with add_NavigationCompleted.

remove_NavigationStarting
HRESULT remove_NavigationStarting(EventRegistrationToken token)

Remove an event handler previously added with add_NavigationStarting.

remove_WebMessageReceived
HRESULT remove_WebMessageReceived(EventRegistrationToken token)

Remove an event handler previously added with add_WebMessageReceived.

Inherited Members

From ICoreWebView2Frame

get_Name
HRESULT get_Name(LPWSTR* name)

The name of the iframe from the iframe html tag declaring it. You can access this property even if the iframe is destroyed.

add_NameChanged
HRESULT add_NameChanged(ICoreWebView2FrameNameChangedEventHandler eventHandler, EventRegistrationToken* token)

Raised when the iframe changes its window.name property.

remove_NameChanged
HRESULT remove_NameChanged(EventRegistrationToken token)

Remove an event handler previously added with add_NameChanged.

AddHostObjectToScriptWithOrigins
HRESULT AddHostObjectToScriptWithOrigins(LPCWSTR name, VARIANT* object, UINT32 originsCount, LPCWSTR* origins)

Add the provided host object to script running in the iframe with the specified name for the list of the specified origins. The host object will be accessible for this iframe only if the iframe's origin during access matches one of the origins which are passed. The provided origins will be normalized before comparing to the origin of the document. So the scheme name is made lower case, the host will be punycode decoded as appropriate, default port values will be removed, and so on. This means the origin's host may be punycode encoded or not and will match regardless. If list contains malformed origin the call will fail. The method can be called multiple times in a row without calling RemoveHostObjectFromScript for the same object name. It will replace the previous object with the new object and new list of origins. List of origins will be treated as following: 1. empty list - call will succeed and object will be added for the iframe but it will not be exposed to any origin; 2. list with origins - during access to host object from iframe the origin will be checked that it belongs to this list; 3. list with "*" element - host object will be available for iframe for all origins. We suggest not to use this feature without understanding security implications of giving access to host object from from iframes with unknown origins. 4. list with "file://" element - host object will be available for iframes loaded via file protocol. Calling this method fails if it is called after the iframe is destroyed. \snippet ScenarioAddHostObject.cpp AddHostObjectToScriptWithOrigins For more information about host objects navigate to ICoreWebView2::AddHostObjectToScript.

RemoveHostObjectFromScript
HRESULT RemoveHostObjectFromScript(LPCWSTR name)

Remove the host object specified by the name so that it is no longer accessible from JavaScript code in the iframe. While new access attempts are denied, if the object is already obtained by JavaScript code in the iframe, the JavaScript code continues to have access to that object. Calling this method for a name that is already removed or was never added fails. If the iframe is destroyed this method will return fail also.

add_Destroyed
HRESULT add_Destroyed(ICoreWebView2FrameDestroyedEventHandler eventHandler, EventRegistrationToken* token)

The Destroyed event is raised when the iframe corresponding to this CoreWebView2Frame object is removed or the document containing that iframe is destroyed.

remove_Destroyed
HRESULT remove_Destroyed(EventRegistrationToken token)

Remove an event handler previously added with add_Destroyed.

IsDestroyed
HRESULT IsDestroyed(BOOL* destroyed)

Check whether a frame is destroyed. Returns true during the Destroyed event.

Meta