public static async Task <SizeI> WebViewContentSizeAsync(this Windows.UI.Xaml.Controls.WebView webView)
        {
            var widthString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollWidth.toString()" });

            if (!int.TryParse(widthString, out int contentWidth))
            {
                throw new Exception(string.Format("failure/width:{0}", widthString));
            }

            Debug.WriteLine("elementHeight = " + webView.Height);

            //var rect = await webView.InvokeScriptAsync("pizzx", new[] { "document.getElementById( 'rasta' ).clientHeight.toString()" });
            // ask the content its height
            //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.documentElement.scrollHeight.toString()" });
            //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollHeight.toString()" });
            //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.documentElement.getBoundingClientRect().height.toString()" });
            //var heightString = await webView.InvokeScriptAsync("eval", new[] { "self.innerHeight.toString()" });
            //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.offsetHeight.toString()" });
            var heightString = await webView.InvokeScriptAsync("eval", new[] { "Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight ).toString()" });//, document.documentElement.offsetHeight ).toString()" });

            if (!int.TryParse(heightString, out int contentHeight))
            {
                throw new Exception(string.Format("failure/height:{0}", heightString));
            }

            return(new SizeI(contentWidth, contentHeight));
        }
Ejemplo n.º 2
0
        public static async Task <SizeI> WebViewContentSizeAsync(this Windows.UI.Xaml.Controls.WebView webView)
        {
            int contentWidth  = 72 * 8;
            int contentHeight = 72 * 10;

            try
            {
                var widthString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollWidth.toString()" });

                int.TryParse(widthString, out contentWidth);

                Debug.WriteLine("elementHeight = " + webView.Height);

                //var rect = await webView.InvokeScriptAsync("pizzx", new[] { "document.getElementById( 'rasta' ).clientHeight.toString()" });
                // ask the content its height
                //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.documentElement.scrollHeight.toString()" });
                //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollHeight.toString()" });
                //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.documentElement.getBoundingClientRect().height.toString()" });
                //var heightString = await webView.InvokeScriptAsync("eval", new[] { "self.innerHeight.toString()" });
                //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.offsetHeight.toString()" });
                var heightString = await webView.InvokeScriptAsync("eval", new[] { "Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight ).toString()" });//, document.documentElement.offsetHeight ).toString()" });

                int.TryParse(heightString, out contentHeight);
            }
            catch (Exception e)
            {
                await Forms9Patch.Settings.RequestUserHelp(e);
            }
            return(new SizeI(contentWidth, contentHeight));
        }
Ejemplo n.º 3
0
        public static async Task <SizeI> WebViewContentSizeAsync(this Windows.UI.Xaml.Controls.WebView webView, int depth = 0, [System.Runtime.CompilerServices.CallerMemberName] string callerName = null)
        {
            if (webView is null)
            {
                await Forms9Patch.Debug.RequestUserHelp(null, "webView is null.");
            }

            int contentWidth  = 72 * 8;
            int contentHeight = 72 * 10;

            if (depth > 50)
            {
                return(new SizeI(contentWidth, contentHeight));
            }
            if (depth > 0)
            {
                await Task.Delay(100);
            }

            int line = P42.Utils.ReflectionExtensions.CallerLineNumber();

            try
            {
                line = P42.Utils.ReflectionExtensions.CallerLineNumber();
                var widthString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollWidth.toString()" });

                line = P42.Utils.ReflectionExtensions.CallerLineNumber();
                int.TryParse(widthString, out contentWidth);
                line = P42.Utils.ReflectionExtensions.CallerLineNumber();

                System.Diagnostics.Debug.WriteLine("elementHeight = " + webView.Height);

                //var rect = await webView.InvokeScriptAsync("pizzx", new[] { "document.getElementById( 'rasta' ).clientHeight.toString()" });
                // ask the content its height
                //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.documentElement.scrollHeight.toString()" });
                //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollHeight.toString()" });
                //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.documentElement.getBoundingClientRect().height.toString()" });
                //var heightString = await webView.InvokeScriptAsync("eval", new[] { "self.innerHeight.toString()" });
                //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.offsetHeight.toString()" });
                line = P42.Utils.ReflectionExtensions.CallerLineNumber();
                var heightString = await webView.InvokeScriptAsync("eval", new[] { "Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight ).toString()" });//, document.documentElement.offsetHeight ).toString()" });

                line = P42.Utils.ReflectionExtensions.CallerLineNumber();
                int.TryParse(heightString, out contentHeight);
                line = P42.Utils.ReflectionExtensions.CallerLineNumber();
            }
            catch (Exception e)
            {
                //await Forms9Patch.Debug.RequestUserHelp(e, "line = " + line + ", callerName=["+callerName+"]");
                System.Diagnostics.Debug.WriteLine("UwpWebViewExtensions.WebViewContentSizeAsync FAIL");
                return(await WebViewContentSizeAsync(webView, depth + 1, callerName));
            }
            return(new SizeI(contentWidth, contentHeight));
        }
Ejemplo n.º 4
0
        public static async Task <SizeI> WebViewContentSizeAsync(this Windows.UI.Xaml.Controls.WebView webView)
        {
            var widthString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollWidth.toString()" });

            if (!int.TryParse(widthString, out int contentWidth))
            {
                throw new Exception(string.Format("failure/width:{0}", widthString));
            }

            // ask the content its height
            var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollHeight.toString()" });

            if (!int.TryParse(heightString, out int contentHeight))
            {
                throw new Exception(string.Format("failure/height:{0}", heightString));
            }

            return(new SizeI(contentWidth, contentHeight));
        }
        public WebContentFetcher()
        {
            WebViewInstance = new Windows.UI.Xaml.Controls.WebView();
            //WebViewInstance.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            WebViewInstance.NavigationStarting +=
                async(sender, e) =>
            {
                Debug.WriteLine("Starting NavigationStarting");
                Navigating = true;
                await Task.Delay(4000);

                if (Navigating)
                {
                    Debug.WriteLine("Time exceeds");
                    e.Cancel    = true;
                    Navigating  = false;
                    Fetching    = false;
                    HtmlContent = "";
                }
                Debug.WriteLine("End NavigationStarting");
            };
            WebViewInstance.NavigationCompleted +=
                async(sender, e) =>
            {
                Debug.WriteLine("Starting NavigationCompleted");
                Navigating  = false;
                HtmlContent = await WebViewInstance.InvokeScriptAsync("eval", new string[1] {
                    "document.doctype"
                });

                HtmlContent += await WebViewInstance.InvokeScriptAsync("eval", new string[1] {
                    "document.documentElement.outerHTML"
                });

                if (!e.IsSuccess)
                {
                    await Task.Delay(500);
                }
                Fetching = false;
                Debug.WriteLine("End NavigationCompleted");
            };
        }
Ejemplo n.º 6
0
        public static void EvalJS(WebBrowser browser, string js)
        {
            try
            {
#if MAST_PHONE
                browser.InvokeScript("eval", new string[] { js });
#elif MAST_STORE
                await browser.InvokeScriptAsync("eval", new string[] { js });
#endif
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("EvalJS:" + ex.Message);
                // TODO: Bubble this up.
            }
        }
        private async void WebView_NavigationCompleted(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationCompletedEventArgs args)
        {
            string docClickScript = @"if (document.addEventListener) {" +
                                    "document.addEventListener(\"click\", PageClicked, false);" +
                                    "} else {" +
                                    "document.attachEvent('onclick', PageClicked);" +
                                    "}  " +
                                    "function PageClicked(event){" +
                                    "var pointX = event.clientX;" +
                                    "var pointY = event.clientY;" +
                                    " window.external.notify('tap:' + pointX + ':' + pointY);" +
                                    "}";
            await sender.InvokeScriptAsync("eval", new string[] { docClickScript }); //set event 'click' on page

            RingContentVisibility = false;
            RingText = screeningText;
        }
Ejemplo n.º 8
0
        public static async Task <string> GetHtml(this Windows.UI.Xaml.Controls.WebView webView)
        {
            string html = await webView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });

            return(html);
        }
Ejemplo n.º 9
0
        public static void EvalJS(WebBrowser browser, string js)
        {
            try
            {
#if MAST_PHONE
                browser.InvokeScript("eval", new string[] { js });
#elif MAST_STORE
                await browser.InvokeScriptAsync("eval", new string[] { js });
#endif
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("EvalJS:" + ex.Message);
                // TODO: Bubble this up.
            }
        }
Ejemplo n.º 10
0
 private static async void Browser_NavigationCompleted(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationCompletedEventArgs args)
 {
     await sender.InvokeScriptAsync("eval", new[] { DisableScrollingJs });
 }