public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
 {
     webView.EvaluateJavaScript("callCsharp()", (result, error) =>
     {
         if (error != null) Console.WriteLine(error);
     });
 }
Exemplo n.º 2
0
 public void Submit(string functionName, SubmitDataModel model)
 {
     _webView.InvokeOnMainThread(() =>
     {
         _webView.EvaluateJavaScript($"{functionName}({model.InvokeData});", null);
     });
 }
Exemplo n.º 3
0
        protected override bool ShouldStartLoad(WKWebView webView, WKNavigationAction navigationAction)
        {
            var url = navigationAction.Request.Url;

            if (url != null && url.Scheme.Equals("app"))
            {
                var func = url.Host;

                if (func.Equals("ready"))
                {
                    _domLoaded = true;
                    foreach (var e in _toBeExecuted)
                    {
                        webView.EvaluateJavaScript(e, null);
                    }
                }
                else if (func.Equals("comment"))
                {
                    var commentModel = JsonConvert.DeserializeObject <JavascriptCommentModel>(UrlDecode(url.Fragment));
                    PromptForComment(commentModel);
                }

                return(false);
            }

            return(base.ShouldStartLoad(webView, navigationAction));
        }
Exemplo n.º 4
0
 public TEditorViewController() : base()
 {
     _richTextEditor = new TEditor.Abstractions.TEditor();
     _richTextEditor.SetJavaScriptEvaluatingFunction((input) =>
     {
         _webView.EvaluateJavaScript(input, (_, __) => { });
     });
     _richTextEditor.SetJavaScriptEvaluatingWithResultFunction((input) =>
     {
         return(Task.Run <string>(() =>
         {
             string res = string.Empty;
             InvokeOnMainThread(() =>
             {
                 _webView.EvaluateJavaScript(input, (v, __) => res = v as NSString);
             });
             return res;
         }));
     });
 }
Exemplo n.º 5
0
        public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
        {
            WKJavascriptEvaluationResult handler = (NSObject result, NSError error) => {
                if (error != null)
                {
                    Console.WriteLine(result.ToString());
                }
            };

            webView.EvaluateJavaScript(HtmlCode, handler);
        }
        public void DidReceiveScriptMessage(WKUserContentController userContentController, WKScriptMessage message)
        {
            var parsed    = getParsedJSON(message.Body);
            var callback  = parsed.ObjectForKey(new NSString("callback")) as NSString;
            var urlscheme = parsed.ObjectForKey(new NSString("urlscheme")) as NSString;

            var success    = UIApplication.SharedApplication.OpenUrl(NSUrl.FromString(urlscheme));
            var successStr = success.ToString().ToLower(); // "Bool" to "bool"
            var js         = new NSString($"{callback}({successStr}, \"{urlscheme}\")");

            _webView?.EvaluateJavaScript(js, null);
        }
Exemplo n.º 7
0
        public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
        {
            NavigationFinished();

            webView.EvaluateJavaScript("document.body.getBoundingClientRect().bottom", completionHandler: (heightHeight, heightError) =>
            {
                if (heightError != null)
                {
                    LogHelper.LogUserMessage("WKNavigationDelegate:DidFinishNavigation", GetLogInfo + " " + heightError.Description);
                }
            });
        }
Exemplo n.º 8
0
            public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
            {
                //If the page don't allow zoom, insert metatag to allow it
                string allowZoom = @"javascript:
                    var newMeta = document.createElement('meta');
                    newMeta.setAttribute('name', 'viewport');
                    newMeta.setAttribute('content', 'user-scalable=yes, width=device-width');
                    document.getElementsByTagName('head')[0].appendChild(newMeta);";

                webView.EvaluateJavaScript(allowZoom, null);

                _webView = webView;
            }
Exemplo n.º 9
0
        public void AddUrlOverride(string url, Func <string> action)
        {
            if (_webView == null)
            {
                throw new System.Exception("WebView and WebViewClient were not initialized");
            }

            _webViewClient.AddOverrideUrl(url, action);

            var schemeHandler = new TrestleSchemeHandler();

            schemeHandler.AddOverrideUrl(url, action);

            _configuration.SetUrlSchemeHandler(schemeHandler, "trestle");

            _webView.EvaluateJavaScript("document.documentElement.outerHTML.toString()", (NSObject result, NSError err) => {
                if (err != null)
                {
                    System.Console.WriteLine(err);
                }
                if (result != null)
                {
                    _html = result.ToString();
                }
            });

            _webView.RemoveFromSuperview();
            _webView = new WKWebView(_layout.Bounds, _configuration);
            _webView.TranslatesAutoresizingMaskIntoConstraints = false;

            _webView.NavigationDelegate = _webViewClient;

            _layout.AddSubview(_webView);
            NSLayoutConstraint.Create(_webView, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, _layout, NSLayoutAttribute.CenterX, 1f, 0f).Active = true;
            NSLayoutConstraint.Create(_webView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, _layout, NSLayoutAttribute.CenterY, 1f, 0f).Active = true;
            _webView.SetNeedsDisplay();
            _webView.LoadHtmlString(_html, null);
        }
Exemplo n.º 10
0
        public void DidReceiveScriptMessage(WKUserContentController userContentController, WKScriptMessage message)
        {
            var msg = message.Body.ToString();

            System.Diagnostics.Debug.WriteLine(msg);

            //C# call JavaScript
            webview_real.EvaluateJavaScript("ChangeValue('" + msg + "')", (result, error) =>
            {
                if (error != null)
                {
                    Console.WriteLine(error);
                }
            });
        }
Exemplo n.º 11
0
        private void ExecuteScript(string script)
        {
            if (_isLoading)
            {
                return;
            }

            try
            {
                _baseWebView.EvaluateJavaScript(script, null);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"Error executing script in HeatMapLayer: {ex}");
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Implementación por/plataforma de la solicitud del identificador de la sesión.
        /// </summary>
        /// <param name="merchantId">El identificador del cliente</param>
        /// <param name="apiKey">La llave pública del API del cliente</param>
        /// <param name="baseUrl">El URL al que se debe conectar la plataforma.</param>
        protected override Task <string> CreateDeviceSessionIdInternal(string merchantId, string apiKey, string baseUrl)
        {
            var sessionId = Guid.NewGuid().ToString().Replace("-", string.Empty);

            var identifierForVendor       = UIDevice.CurrentDevice.IdentifierForVendor.AsString().Replace("-", string.Empty);
            var identifierForVendorScript = $"var identifierForVendor = '{identifierForVendor}';";

            using (WKWebView webView = new WKWebView(CGRect.Empty, new WKWebViewConfiguration()))
            {
                webView.EvaluateJavaScript(identifierForVendor, null);

                var url = $"{baseUrl}/oa/logo.htm?m={merchantId}&s={sessionId}";
                webView.LoadRequest(new NSUrlRequest(new NSUrl(url)));
            }

            return(Task.FromResult(sessionId));
        }
Exemplo n.º 13
0
        public async void CheckReloadWebView(CancellationToken token, WKWebView webView)
        {
            try
            {
                await Task.Delay(5000, token);

                webView.EvaluateJavaScript("document.body.getBoundingClientRect().bottom", completionHandler: (height, error) =>
                {
                    if (!IsDisappeared && (error != null || String.IsNullOrWhiteSpace(height.Description) || int.Parse(height.Description) < 4))
                    {
                        Platform.ClearBrowserCache();
                        webView.LoadHtmlString(Challenge.Desc, null);
                    }
                });
            }
            catch (Exception) { }
        }
Exemplo n.º 14
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // this is the default blue color; OWA does not seem to allow you to change themes,
            // but we will nevertheless fetch this value again from CSS when it's loaded
            UpdateTheme(UIColor.FromRGB(0, 120, 215));

            var webView = new WKWebView(
                CGRect.Empty,
                new WKWebViewConfiguration {
                UserContentController = new ContentController(this)
            })
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                AllowsBackForwardNavigationGestures       = false,
                UIDelegate = this
            };

            View.AddSubview(webView);

            var layoutGuide = View.SafeAreaLayoutGuide;

            webView.LeadingAnchor.ConstraintEqualTo(layoutGuide.LeadingAnchor).Active   = true;
            webView.TrailingAnchor.ConstraintEqualTo(layoutGuide.TrailingAnchor).Active = true;
            webView.TopAnchor.ConstraintEqualTo(layoutGuide.TopAnchor).Active           = true;
            webView.BottomAnchor.ConstraintEqualTo(layoutGuide.BottomAnchor).Active     = true;

            // OWA does not behave well with main-frame scrolling in Safari,
            // so disable it here ... all of the scrolling we care about will
            // come from an overflow div, etc.
            webView.ScrollView.ScrollEnabled = false;
            webView.ScrollView.Bounces       = false;

            webView.LoadRequest(new NSUrlRequest(new NSUrl("https://outlook.office.com/owa")));

            webView.AddGestureRecognizer(new UIScreenEdgePanGestureRecognizer(gesture => {
                if (gesture.State == UIGestureRecognizerState.Ended)
                {
                    webView.EvaluateJavaScript("_showa_goBack()", (result, error) => { });
                }
            })
            {
                Edges = UIRectEdge.Left
            });
        }
Exemplo n.º 15
0
        public Task <string> GetSystemUserAgent()
        {
            var taskCompletionSource = new TaskCompletionSource <string>();
            var webView = new WKWebView(CGRect.Empty, new WKWebViewConfiguration());

            webView.EvaluateJavaScript("navigator.userAgent", (NSObject result, NSError err) =>
            {
                if (result != null && result is NSString resultString)
                {
                    taskCompletionSource.TrySetResult(resultString.ToString());
                    return;
                }

                // Return empty string if it failed.
                taskCompletionSource.TrySetResult(String.Empty);
            });
            return(taskCompletionSource.Task);
        }
        public void DidReceiveScriptMessage(WKUserContentController userContentController, WKScriptMessage message)
        {
            try
            {
                var parsed = GetParsedJSON(message.Body.Description as object);

                var callback  = parsed["callback"].ToString();
                var urlscheme = parsed["urlscheme"].ToString();
                var appUrl    = new NSUrl(urlscheme);

                var canOpenApplicationUrl = UIApplication.SharedApplication.CanOpenUrl(appUrl);

                if (canOpenApplicationUrl)
                {
                    UIApplication.SharedApplication.OpenUrl(appUrl);
                }

                var js = string.Format("{0}({1},\"{2}\");", callback, canOpenApplicationUrl.ToString().ToLowerInvariant(), urlscheme);

                webView.EvaluateJavaScript(js, null);
            }
            catch { }
        }
        private void EvaluateJava()
        {
            WKJavascriptEvaluationResult handler = HandleWKJavascriptEvaluationResult;

            wkWebView.EvaluateJavaScript((NSString)@"navigator.userAgent", handler);
        }
Exemplo n.º 18
0
 private void Callback(string result)
 {
     webview_real.EvaluateJavaScript($"Callback('{result}')", null);
 }
Exemplo n.º 19
0
 public static void CallJavascript(string script)
 {
     _webView.EvaluateJavaScript(script, null);
 }
Exemplo n.º 20
0
        protected override bool ShouldStartLoad(WKWebView webView, WKNavigationAction navigationAction)
        {
            var url = navigationAction.Request.Url;
			if(url != null && url.Scheme.Equals("app")) {
                var func = url.Host;

				if (func.Equals("ready"))
				{
					_domLoaded = true;
					foreach (var e in _toBeExecuted)
                        webView.EvaluateJavaScript(e, null);
				}
				else if(func.Equals("comment")) 
				{
                    var commentModel = JsonConvert.DeserializeObject<JavascriptCommentModel>(UrlDecode(url.Fragment));
					PromptForComment(commentModel);
                }

				return false;
            }

            return base.ShouldStartLoad(webView, navigationAction);
        }