fix #1455
This commit is contained in:
parent
459875ff2e
commit
0f1c7e3029
|
@ -1,3 +1,7 @@
|
|||
## 6.0.0-beta.21
|
||||
|
||||
- Fixed "Android plugin version 6 - UserScripts not executing on new tabs." [#1455](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1455)
|
||||
|
||||
## 6.0.0-beta.20
|
||||
|
||||
- Using Android `WebViewClientCompat` for Chromium-based WebView if the WebView package major version is >= 73 (https://bugs.chromium.org/p/chromium/issues/detail?id=925887)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.pichillilorenzo.flutter_inappwebview.webview.in_app_webview;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.os.Build;
|
||||
|
@ -88,7 +89,12 @@ public class FlutterWebView implements PlatformWebView {
|
|||
return pullToRefreshLayout != null ? pullToRefreshLayout : webView;
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
public void makeInitialLoad(HashMap<String, Object> params) {
|
||||
if (webView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Integer windowId = (Integer) params.get("windowId");
|
||||
Map<String, Object> initialUrlRequest = (Map<String, Object>) params.get("initialUrlRequest");
|
||||
final String initialFile = (String) params.get("initialFile");
|
||||
|
@ -99,6 +105,23 @@ public class FlutterWebView implements PlatformWebView {
|
|||
if (resultMsg != null) {
|
||||
((WebView.WebViewTransport) resultMsg.obj).setWebView(webView);
|
||||
resultMsg.sendToTarget();
|
||||
if (WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT)) {
|
||||
// for some reason, if a WebView is created using a window id,
|
||||
// the initial plugin and user scripts injected
|
||||
// with WebViewCompat.addDocumentStartJavaScript will not be added!
|
||||
// https://github.com/pichillilorenzo/flutter_inappwebview/issues/1455
|
||||
//
|
||||
// Also, calling the prepareAndAddUserScripts method right after won't work,
|
||||
// so use the View.post method here.
|
||||
webView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (webView != null) {
|
||||
webView.prepareAndAddUserScripts();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (initialFile != null) {
|
||||
|
|
|
@ -61,7 +61,6 @@ import androidx.webkit.WebViewCompat;
|
|||
import androidx.webkit.WebViewFeature;
|
||||
|
||||
import com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin;
|
||||
import com.pichillilorenzo.flutter_inappwebview.InAppWebViewStatic;
|
||||
import com.pichillilorenzo.flutter_inappwebview.R;
|
||||
import com.pichillilorenzo.flutter_inappwebview.Util;
|
||||
import com.pichillilorenzo.flutter_inappwebview.content_blocker.ContentBlocker;
|
||||
|
@ -166,7 +165,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
|
|||
public Map<String, WebMessageChannel> webMessageChannels = new HashMap<>();
|
||||
public List<WebMessageListener> webMessageListeners = new ArrayList<>();
|
||||
|
||||
private List<UserScript> initialUserOnlyScript = new ArrayList<>();
|
||||
private List<UserScript> initialUserOnlyScripts = new ArrayList<>();
|
||||
|
||||
@Nullable
|
||||
public FindInteractionController findInteractionController;
|
||||
|
@ -198,7 +197,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
|
|||
this.windowId = windowId;
|
||||
this.customSettings = customSettings;
|
||||
this.contextMenu = contextMenu;
|
||||
this.initialUserOnlyScript = userScripts;
|
||||
this.initialUserOnlyScripts = userScripts;
|
||||
if (plugin != null && plugin.activity != null) {
|
||||
plugin.activity.registerForContextMenu(this);
|
||||
}
|
||||
|
@ -260,7 +259,13 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
|
|||
WebViewCompat.setWebViewRenderProcessClient(this, inAppWebViewRenderProcessClient);
|
||||
}
|
||||
|
||||
if (windowId == null || !WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT)) {
|
||||
// for some reason, if a WebView is created using a window id,
|
||||
// the initial plugin and user scripts injected
|
||||
// with WebViewCompat.addDocumentStartJavaScript will not be added!
|
||||
// https://github.com/pichillilorenzo/flutter_inappwebview/issues/1455
|
||||
prepareAndAddUserScripts();
|
||||
}
|
||||
|
||||
if (customSettings.useOnDownloadStart)
|
||||
setDownloadListener(new DownloadStartListener());
|
||||
|
@ -552,7 +557,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
|
|||
});
|
||||
}
|
||||
|
||||
private void prepareAndAddUserScripts() {
|
||||
public void prepareAndAddUserScripts() {
|
||||
userContentController.addPluginScript(PromisePolyfillJS.PROMISE_POLYFILL_JS_PLUGIN_SCRIPT);
|
||||
userContentController.addPluginScript(JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_JS_PLUGIN_SCRIPT);
|
||||
userContentController.addPluginScript(ConsoleLogJS.CONSOLE_LOG_JS_PLUGIN_SCRIPT);
|
||||
|
@ -571,7 +576,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
|
|||
if (!customSettings.useHybridComposition) {
|
||||
userContentController.addPluginScript(PluginScriptsUtil.CHECK_GLOBAL_KEY_DOWN_EVENT_TO_HIDE_CONTEXT_MENU_JS_PLUGIN_SCRIPT);
|
||||
}
|
||||
this.userContentController.addUserOnlyScripts(this.initialUserOnlyScript);
|
||||
this.userContentController.addUserOnlyScripts(this.initialUserOnlyScripts);
|
||||
}
|
||||
|
||||
public void setIncognito(boolean enabled) {
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
export "FLUTTER_ROOT=/Users/lorenzopichilli/fvm/versions/3.3.6"
|
||||
export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example"
|
||||
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
|
||||
export "FLUTTER_TARGET=integration_test/webview_flutter_test.dart"
|
||||
export "FLUTTER_TARGET=lib/main.dart"
|
||||
export "FLUTTER_BUILD_DIR=build"
|
||||
export "FLUTTER_BUILD_NAME=1.0.0"
|
||||
export "FLUTTER_BUILD_NUMBER=1"
|
||||
export "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
|
||||
export "DART_OBFUSCATION=false"
|
||||
export "TRACK_WIDGET_CREATION=true"
|
||||
export "TREE_SHAKE_ICONS=false"
|
||||
export "PACKAGE_CONFIG=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example/.dart_tool/package_config.json"
|
||||
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: flutter_inappwebview
|
||||
description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window.
|
||||
version: 6.0.0-beta.20
|
||||
version: 6.0.0-beta.21
|
||||
homepage: https://inappwebview.dev/
|
||||
repository: https://github.com/pichillilorenzo/flutter_inappwebview
|
||||
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
|
||||
|
|
Loading…
Reference in New Issue