From 3087bbbc0eb904fb43288a9703dfc103c78c1620 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Tue, 26 Apr 2022 12:16:47 +0200 Subject: [PATCH] added static WebView.debugLogging --- lib/src/in_app_browser/in_app_browser.dart | 3 ++- .../in_app_webview_controller.dart | 17 +++++++++++++++++ lib/src/in_app_webview/webview.dart | 4 ++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/src/in_app_browser/in_app_browser.dart b/lib/src/in_app_browser/in_app_browser.dart index 85d97d47..b72c02a7 100755 --- a/lib/src/in_app_browser/in_app_browser.dart +++ b/lib/src/in_app_browser/in_app_browser.dart @@ -493,7 +493,8 @@ class InAppBrowser { ///[InAppWebViewSettings.enableViewportScale], [InAppWebViewSettings.allowsAirPlayForMediaPlayback], ///[InAppWebViewSettings.allowsPictureInPictureMediaPlayback], [InAppWebViewSettings.isFraudulentWebsiteWarningEnabled], ///[InAppWebViewSettings.allowsInlineMediaPlayback], [InAppWebViewSettings.suppressesIncrementalRendering], [InAppWebViewSettings.selectionGranularity], - ///[InAppWebViewSettings.ignoresViewportScaleLimits], + ///[InAppWebViewSettings.ignoresViewportScaleLimits], [InAppWebViewSettings.limitsNavigationsToAppBoundDomains], + ///[InAppWebViewSettings.upgradeKnownHostsToHTTPS], ///will have no effect due to a `WKWebView` limitation when creating a new window WebView: it's impossible to return a new `WKWebView` ///with a different `WKWebViewConfiguration` instance (see https://developer.apple.com/documentation/webkit/wkuidelegate/1536907-webview). ///So, these options will be inherited from the caller 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 12dab288..51cc5501 100644 --- a/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/in_app_webview_controller.dart @@ -3,6 +3,7 @@ import 'dart:collection'; import 'dart:typed_data'; import 'dart:convert'; import 'dart:core'; +import 'dart:developer' as developer; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -105,6 +106,14 @@ class InAppWebViewController } Future handleMethod(MethodCall call) async { + + if (WebView.debugLogging && (call.method.startsWith("on") || call.method.startsWith("should")) && + call.method != "onCallJsHandler") { + developer.log( + call.method.toString() + ": using " + call.arguments.toString(), + name: this.runtimeType.toString()); + } + switch (call.method) { case "onLoadStart": _injectedScriptsFromURL.clear(); @@ -951,7 +960,9 @@ class InAppWebViewController ContextMenuItem menuItemClicked = ContextMenuItem( id: id, + // ignore: deprecated_member_use_from_same_package androidId: androidId, + // ignore: deprecated_member_use_from_same_package iosId: iosId, title: title, action: null); @@ -1021,6 +1032,12 @@ class InAppWebViewController // decode args to json List args = jsonDecode(call.arguments["args"]); + if (WebView.debugLogging && (handlerName.startsWith("on") || handlerName.startsWith("should"))) { + developer.log( + handlerName.toString() + ": using " + args.toString(), + name: this.runtimeType.toString()); + } + switch (handlerName) { case "onLoadResource": if ((_webview != null && _webview!.onLoadResource != null) || diff --git a/lib/src/in_app_webview/webview.dart b/lib/src/in_app_webview/webview.dart index 4028fa72..4c665bd7 100644 --- a/lib/src/in_app_webview/webview.dart +++ b/lib/src/in_app_webview/webview.dart @@ -12,6 +12,9 @@ import 'headless_in_app_webview.dart'; ///Abstract class that represents a WebView. Used by [InAppWebView] and [HeadlessInAppWebView]. abstract class WebView { + ///Enables WebView debug logging info. Logging is on by default. + static bool debugLogging = true; + ///The window id of a [CreateWindowAction.windowId]. final int? windowId; @@ -187,6 +190,7 @@ abstract class WebView { ///[InAppWebViewSettings.allowsPictureInPictureMediaPlayback], [InAppWebViewSettings.isFraudulentWebsiteWarningEnabled], ///[InAppWebViewSettings.allowsInlineMediaPlayback], [InAppWebViewSettings.suppressesIncrementalRendering], [InAppWebViewSettings.selectionGranularity], ///[InAppWebViewSettings.ignoresViewportScaleLimits], [InAppWebViewSettings.limitsNavigationsToAppBoundDomains], + ///[InAppWebViewSettings.upgradeKnownHostsToHTTPS], ///will have no effect due to a `WKWebView` limitation when creating the new window WebView: it's impossible to return the new `WKWebView` ///with a different `WKWebViewConfiguration` instance (see https://developer.apple.com/documentation/webkit/wkuidelegate/1536907-webview). ///So, these options will be inherited from the caller WebView.