/// <summary> /// Add the provided JavaScript to a list of scripts /// that should be executed 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 executed. The /// injected script will apply to all future top level document and child /// frame navigations until removed with RemoveScriptToExecuteOnDocumentCreated. /// This is applied asynchronously and you must wait for the completion /// handler to run before you can be sure that the script is ready to /// execute on future navigations. /// /// Note that if an HTML document has sandboxing of some kind via [sandbox](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox) /// properties or the [Content-Security-Policy HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) /// 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. /// </summary> /// <param name="javaScript"></param> /// <param name="handler"></param> public void AddScriptToExecuteOnDocumentCreated(string javaScript, Action <AddScriptToExecuteOnDocumentCreatedCompletedEventArgs> callback) { if (_webView2WebView == null) { return; } if (string.IsNullOrEmpty(javaScript)) { throw new ArgumentNullException("javaScript"); } _webView2WebView.AddScriptToExecuteOnDocumentCreated(javaScript, callback); }