diff --git a/example/lib/in_app_webiew_example.screen.dart b/example/lib/in_app_webiew_example.screen.dart index 7dd0595c..18a5607a 100755 --- a/example/lib/in_app_webiew_example.screen.dart +++ b/example/lib/in_app_webiew_example.screen.dart @@ -169,6 +169,7 @@ class _InAppWebViewExampleScreenState extends State { this.url = url.toString(); urlController.text = this.url; }); + }, onLoadError: (controller, url, code, message) { pullToRefreshController?.endRefreshing(); diff --git a/lib/assets/web/web_support.js b/lib/assets/web/web_support.js index 472c9cae..96444d79 100644 --- a/lib/assets/web/web_support.js +++ b/lib/assets/web/web_support.js @@ -497,6 +497,51 @@ window.flutter_inappwebview = { } return null; }, + getScrollX: function() { + var iframe = webView.iframe; + try { + return Math.round(iframe.contentWindow.scrollX); + } catch (e) { + console.log(e); + } + return null; + }, + getScrollY: function() { + var iframe = webView.iframe; + try { + return Math.round(iframe.contentWindow.scrollY); + } catch (e) { + console.log(e); + } + return null; + }, + isSecureContext: function() { + var iframe = webView.iframe; + try { + return iframe.contentWindow.isSecureContext; + } catch (e) { + console.log(e); + } + return false; + }, + canScrollVertically: function() { + var iframe = webView.iframe; + try { + return iframe.contentDocument.body.scrollHeight > iframe.contentWindow.innerHeight; + } catch (e) { + console.log(e); + } + return false; + }, + canScrollHorizontally: function() { + var iframe = webView.iframe; + try { + return iframe.contentDocument.body.scrollWidth > iframe.contentWindow.innerWidth; + } catch (e) { + console.log(e); + } + return false; + }, }; return webView; diff --git a/lib/src/in_app_webview/in_app_webview_controller.dart b/lib/src/in_app_webview/in_app_webview_controller.dart index 2b52e0a1..50dfd24d 100644 --- a/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/in_app_webview_controller.dart @@ -2488,9 +2488,12 @@ class InAppWebViewController ///Returns the scrolled left position of the current WebView. /// + ///**NOTE for Web**: this method will have effect only if the iframe has the same origin. + /// ///**Supported Platforms/Implementations**: ///- Android native WebView ([Official API - View.getScrollX](https://developer.android.com/reference/android/view/View#getScrollX())) ///- iOS ([Official API - UIScrollView.contentOffset](https://developer.apple.com/documentation/uikit/uiscrollview/1619404-contentoffset)) + ///- Web ([Official API - Window.scrollX](https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollX)) Future getScrollX() async { Map args = {}; return await _channel.invokeMethod('getScrollX', args); @@ -2498,9 +2501,12 @@ class InAppWebViewController ///Returns the scrolled top position of the current WebView. /// + ///**NOTE for Web**: this method will have effect only if the iframe has the same origin. + /// ///**Supported Platforms/Implementations**: ///- Android native WebView ([Official API - View.getScrollY](https://developer.android.com/reference/android/view/View#getScrollY())) ///- iOS ([Official API - UIScrollView.contentOffset](https://developer.apple.com/documentation/uikit/uiscrollview/1619404-contentoffset)) + ///- Web ([Official API - Window.scrollY](https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY)) Future getScrollY() async { Map args = {}; return await _channel.invokeMethod('getScrollY', args); @@ -2731,9 +2737,12 @@ class InAppWebViewController /// ///**NOTE for Android**: available Android 21.0+. /// + ///**NOTE for Web**: this method will have effect only if the iframe has the same origin. Returns `false` otherwise. + /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS + ///- Web ([Official API - Window.isSecureContext](https://developer.mozilla.org/en-US/docs/Web/API/Window/isSecureContext)) Future isSecureContext() async { Map args = {}; return await _channel.invokeMethod('isSecureContext', args); @@ -2959,9 +2968,12 @@ class InAppWebViewController ///Returns `true` if the webpage can scroll vertically, otherwise `false`. /// + ///**NOTE for Web**: this method will have effect only if the iframe has the same origin. + /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS + ///- Web Future canScrollVertically() async { Map args = {}; return await _channel.invokeMethod('canScrollVertically', args); @@ -2969,9 +2981,12 @@ class InAppWebViewController ///Returns `true` if the webpage can scroll horizontally, otherwise `false`. /// + ///**NOTE for Web**: this method will have effect only if the iframe has the same origin. + /// ///**Supported Platforms/Implementations**: ///- Android native WebView ///- iOS + ///- Web Future canScrollHorizontally() async { Map args = {}; return await _channel.invokeMethod('canScrollHorizontally', args); diff --git a/lib/src/web/in_app_web_view_web_element.dart b/lib/src/web/in_app_web_view_web_element.dart index 774a8f17..90304bee 100644 --- a/lib/src/web/in_app_web_view_web_element.dart +++ b/lib/src/web/in_app_web_view_web_element.dart @@ -136,6 +136,16 @@ class InAppWebViewWebElement { return await getOriginalUrl(); case "getSelectedText": return await getSelectedText(); + case "getScrollX": + return await getScrollX(); + case "getScrollY": + return await getScrollY(); + case "isSecureContext": + return await isSecureContext(); + case "canScrollVertically": + return await canScrollVertically(); + case "canScrollHorizontally": + return await canScrollHorizontally(); case "dispose": dispose(); break; @@ -323,6 +333,26 @@ class InAppWebViewWebElement { return _callMethod('getSelectedText'); } + Future getScrollX() async { + return _callMethod('getScrollX'); + } + + Future getScrollY() async { + return _callMethod('getScrollY'); + } + + Future isSecureContext() async { + return _callMethod('isSecureContext'); + } + + Future canScrollVertically() async { + return _callMethod('canScrollVertically'); + } + + Future canScrollHorizontally() async { + return _callMethod('canScrollHorizontally'); + } + Set getSandbox() { var sandbox = iframe.sandbox; Set values = Set(); diff --git a/scripts/test.sh b/scripts/test.sh index 5cbbadee..a287a45b 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -39,6 +39,6 @@ else FAILED=1 fi -kill $(jobs -p) +jobs -p | xargs kill exit $FAILED \ No newline at end of file