private async void WebView_DOMContentLoaded(WebView sender) { if (!Settings.HaveHardwareButtons) { await sender.InvokeScriptAsync("eval", new[] {HtmlHelper.MarginScript}); } await sender.InvokeScriptAsync("eval", new[] {HtmlHelper.FontColorScript}); }
/// <summary> /// Entry point into the page /// </summary> public MainPage() { this.InitializeComponent(); SetupTitleBar(); CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; LoadingSplash.Visibility = Visibility.Visible; var specuri = localSettings.Values["SPEC"]; if(specuri != null) { FileWebView = new WebView(WebViewExecutionMode.SeparateThread); FileWebView.Name = "FileWebView"; FileWebView.Source = new Uri(specuri as string); FileWebView.ScriptNotify += FileWebView_ScriptNotify; FileWebView.LoadCompleted += async (object sender, Windows.UI.Xaml.Navigation.NavigationEventArgs e) => { //Inject the scripts into the page string scriptstring = await FileIO.ReadTextAsync(await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("Graffiti.js")); FileWebView.InvokeScriptAsync("eval", new List<string> { scriptstring }); //Call the loop that marks text and reports what the user has selected FileWebView.InvokeScriptAsync("GetSelectedText", new List<string> { }); //Load the annotations from the database await LoadAnnotations(GetSpecID(specuri as string)); await AnnotateSpec(); //try to load tests, and if they're loaded display them if (await AttemptLoadCachedTests(GetSpecID(specuri as string))) { TestsList.ItemsSource = nonrecursivetestlist.Tests; } //set up UI UpdateStats(); //try to log in with cached credentials var loginresult = await github.UseCachedLogin(); if (loginresult == "pass") { FinishGitHubLogin(); } //get rid of the splash screen HideLoadingSplash.Begin(); }; FileWebViewParent.Children.Add(FileWebView); } else { HideLoadingSplash.Begin(); } }
public static async Task InitAsync() { if (DesignMode.DesignModeEnabled == false) { WebView webView = new WebView(WebViewExecutionMode.SeparateThread); int width = int.Parse(await webView.InvokeScriptAsync("eval", new string[] { "window.screen.width.toString()" })); int height = int.Parse(await webView.InvokeScriptAsync("eval", new string[] { "window.screen.height.toString()" })); double scale = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel; _width = (int)Math.Ceiling(width * scale); _height = (int)Math.Ceiling(height * scale); } _hadInit = true; }
async Task <WebViewBrush> GetWebViewBrush(Windows.UI.Xaml.Controls.WebView webView) { // resize width to content var _OriginalWidth = webView.Width; var _WidthString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollWidth.toString()" }); int _ContentWidth; if (!int.TryParse(_WidthString, out _ContentWidth)) { throw new Exception(string.Format("failure/width:{0}", _WidthString)); } webView.Width = _ContentWidth; // resize height to content var _OriginalHeight = webView.Height; var _HeightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollHeight.toString()" }); int _ContentHeight; if (!int.TryParse(_HeightString, out _ContentHeight)) { throw new Exception(string.Format("failure/height:{0}", _HeightString)); } webView.Height = _ContentHeight; // create brush var _OriginalVisibilty = webView.Visibility; webView.Visibility = Windows.UI.Xaml.Visibility.Visible; var _Brush = new WebViewBrush { Stretch = Stretch.Uniform, SourceName = webView.Name }; _Brush.Redraw(); // webView.Width = _OriginalWidth; //webView.Height = _OriginalHeight; webView.Visibility = _OriginalVisibilty; return(_Brush); }
private async void TaobaoLogin_DOMContentLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args) { System.Diagnostics.Debug.WriteLine("DOM加载完成"); var inject = @"window.addEventListener('message',function(args){ window.external.notify(args.data); });"; await sender.InvokeScriptAsync("eval", new string[] { inject }); }
private async void WebView_NavigationCompleted(Windows.UI.Xaml.Controls.WebView sender, WebViewNavigationCompletedEventArgs args) { try { //Debug.Write("args.Uri => " + args.Uri); if (args.Uri == null && view.IsChinese) { JWChinese.App.CurrentArticleWords = new ObservableCollection <Word>(); await sender.InvokeScriptAsync("eval", new[] { "annotScan()" }); var words = await StorehouseService.Instance.GetWordsAsync(); string english = string.Join(",", words.Select(w => w.English).ToArray()); string pinyin = string.Join(",", words.Select(w => w.Pinyin).ToArray()); await sender.InvokeScriptAsync("injectWords", new string[] { english, pinyin }); } } catch (Exception ex) { Debug.Write("OOPS! CHECK YOUR JAVASCRIPT => " + ex.Message); } }
private async Task<string> GetHtmlPage(string mangaImageUrl) { wv = new WebView(); //wv.NavigationCompleted += Wv_NavigationCompleted; wv.Navigate(new Uri(mangaImageUrl)); var ss = await WaitForMessageSent(); if (ss.IsSuccess) { _content = await wv.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" }); } return _content; }
public async void CheckingLoginByManualSuccess(WebView webView, bool isLoaded) { if (CheckInternetConnection() || isUserCancel) return; if (!isLoaded) { string[] reauthEmail = new string[] { @"document.getElementById('reauthEmail').innerHTML;" }; string[] emailDisplay = new string[] { @"document.getElementById('email-display').innerHTML;" }; var accountName = string.Empty; try { accountName = await webView.InvokeScriptAsync("eval", reauthEmail); } catch { } try { accountName = await webView.InvokeScriptAsync("eval", emailDisplay); } catch { } if (accountName != string.Empty) account.UserName = accountName; } else { NotifyDownloadStatus(DownloadStatus.LOADING, "..."); bool success = await IsPageSuccess(webView); if (success) { NotifyCloseWebViewForm(); browser.Navigate(new Uri(GOOGLE_OAUTH2_URL)); currentStep = STEP_ACCEPT; return; } else { NotifyDownloadStatus(DownloadStatus.CONTINUE_LOGIN, ""); NotifyOpenWebViewForm(); System.Diagnostics.Debug.WriteLine("open form"); return; } } }
/// <summary> /// Uses WebView control to get the user agent string /// </summary> /// <returns></returns> private static Task<string> GetUserAgent() { var tcs = new TaskCompletionSource<string>(); WebView webView = new WebView(); string htmlFragment = @"<html> <head> <script type='text/javascript'> function GetUserAgent() { return navigator.userAgent; } </script> </head> </html>"; webView.NavigationCompleted += async (sender, e) => { try { //Invoke the javascript when the html load is complete string result = await webView.InvokeScriptAsync("GetUserAgent", null); //Set the task result tcs.TrySetResult(result); } catch(Exception ex) { tcs.TrySetException(ex); } }; //Load Html webView.NavigateToString(htmlFragment); return tcs.Task; }
private async void Webview_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args) { string js = "document.getElementsByClassName('header')[0].style.display='none';"; if (args.Uri.ToString() == "http://m.kugou.com/loginReg.php?act=login&url=http://m.kugou.com") { title.Text = "登录"; } if (args.Uri.ToString() == "http://m.kugou.com/loginReg.php?act=reg&url=http://m.kugou.com") { title.Text = "注册"; } if (args.Uri.ToString()== "http://m.kugou.com/") { js = "window.external.notify(document.cookie)"; } try { await sender.InvokeScriptAsync("eval", new string[] { js }); } catch (Exception) { } }
public static async Task <string> InvokeScriptAsync(Windows.UI.Xaml.Controls.WebView webView, CancellationToken ct, string script, string[] arguments) { return(await webView.InvokeScriptAsync(script, arguments).AsTask(ct)); }
public static string GetHtml(WebView webView) { return webView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" }).GetResults(); }
public async void CheckingLoginByManualSuccess(WebView webView, bool isLoaded) { if (CheckInternetConnection() || isUserCancel) return; if (isLoaded) { NotifyDownloadStatus(DownloadStatus.LOADING, "..."); bool success = await IsPageSuccessWhenImportingtByManual(webView); if (success) { NotifyDownloadStatus(DownloadStatus.PROCESSING, "30%"); await Task.Delay(4000); var accountName = string.Empty; string[] reauthEmail = new string[] { @"document.getElementsByClassName('msame_Drop_active_email')[0].innerText;" }; try { accountName = await webView.InvokeScriptAsync("eval", reauthEmail); } catch { } if (accountName != string.Empty) account.UserName = accountName; System.Diagnostics.Debug.WriteLine("cap nhat username: "******"40%"); currentStep = STEP_ACCEPT; browser.Navigate(new Uri(LIVE_OAUTH2_URL)); } else { NotifyDownloadStatus(DownloadStatus.CONTINUE_LOGIN, ""); NotifyOpenWebViewForm(); System.Diagnostics.Debug.WriteLine("open form"); return; } } }
private async Task<bool> IsPageSuccess(WebView webView) { bool success = false; string[] userArgs = new string[] { @"document.getElementById('yucs-signout').offsetLeft < 0 ? '0':'1';" }; try { var val = await webView.InvokeScriptAsync("eval", userArgs); success = val == "1"; } catch { } return success; }
Task <string> EvaluateJavascript(string script) => Result.InvokeScriptAsync("eval", new string[] { script }).AsTask();
private async void ViewLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args) { //if (!this.IsImageUrl(this.viewModel.SelectedItem.Url)) //{ // return; //} await sender.InvokeScriptAsync("eval", new[] { CssStyle }); }
/// <summary> /// Установить агент. /// </summary> /// <returns>Агент.</returns> public async Task SetDefaultBrowserAgent() { var tcs = new TaskCompletionSource<string>(TaskCreationOptions.None); var ww = new WebView(); ww.NavigateToString(@"<html> <head> <script type='text/javascript'> function getUserAgent() { return navigator.userAgent; } </script> </head> <body> </body> </html>"); ww.NavigationCompleted += async (sender1, e1) => { try { var ua = await ww.InvokeScriptAsync("getUserAgent", new string[0]); tcs.TrySetResult(ua); } catch (Exception ex) { tcs.TrySetException(ex); } }; var task = tcs.Task; var tua = await task; BrowserUserAgent = tua; }
private async Task<bool> IsPageSuccess(WebView webView) { bool hasAccount = false; //var checkArgs = new string[] { @"document.getElementById('shell-header-shopping-cart').offsetLeft < 0 ? '0':'1';" }; var checkArgs = new string[] { @"document.getElementById('idBtn_Accept').offsetLeft < 0 ? '0':'1';" }; try { string val = await webView.InvokeScriptAsync("eval", checkArgs); hasAccount = val == "1"; } catch { } return hasAccount; }