CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync(String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds the provided JavaScript to a list of scripts that should be run after the global object has been created, but before the HTML document has been parsed and before any other script included by the HTML document is run.
public System.Threading.Tasks.Task<string> AddScriptToExecuteOnDocumentCreatedAsync (string javaScript);
member this.AddScriptToExecuteOnDocumentCreatedAsync : string -> System.Threading.Tasks.Task<string>
Public Function AddScriptToExecuteOnDocumentCreatedAsync (javaScript As String) As Task(Of String)
Parameters
- javaScript
- String
The JavaScript code to be run.
Returns
A script ID that may be passed when calling RemoveScriptToExecuteOnDocumentCreated(String).
Remarks
The injected script will apply to all future top level document and child frame navigations until removed with RemoveScriptToExecuteOnDocumentCreated(String). This is applied asynchronously and you must wait for the returned IAsyncOperation to complete before you can be sure that the script is ready to execute on future navigations. If the method is run in NewWindowRequested handler, it should be called before the new window is set. For more details see NewWindow.
Note that if an HTML document has sandboxing of some kind via sandbox properties or the Content-Security-Policy HTTP header this will affect the script run here. So, for example, if the allow-modals
keyword is not set then calls to the alert
function will be ignored.