From a78fad17835f37e55b232427348d02c0c81bf491 Mon Sep 17 00:00:00 2001 From: Norman Breau Date: Sun, 9 Apr 2023 20:41:00 -0300 Subject: [PATCH] feat: InspectableWebview preference (#1589) --- .../cordova/engine/SystemWebViewEngine.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java index 5ff1abff..cbe727cd 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java +++ b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java @@ -175,9 +175,20 @@ public class SystemWebViewEngine implements CordovaWebViewEngine { String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); settings.setDatabaseEnabled(true); - //Determine whether we're in debug or release mode, and turn on Debugging! - ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo(); - if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { + // The default is to use the module's debuggable state to decide if the webview inspecter + // should be enabled. However, users can configure InspectableWebview preference to forcefully enable + // or disable the webview inspecter. + String inspectableWebview = preferences.getString("InspectableWebview", null); + boolean shouldEnableInspector = false; + if (inspectableWebview == null) { + ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo(); + shouldEnableInspector = (appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; + } + else if ("true".equals(inspectableWebview)) { + shouldEnableInspector = true; + } + + if (shouldEnableInspector) { enableRemoteDebugging(); }