From a6607ed3778a3d2ab867111361bd13b5ff9230c3 Mon Sep 17 00:00:00 2001 From: carrick Date: Wed, 30 Oct 2024 09:38:17 +0900 Subject: [PATCH] fix: Modified to manage scripts injected per browser ID --- lib/src/webview_manager.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/src/webview_manager.dart b/lib/src/webview_manager.dart index 7ccfbd4..f9ee6fa 100644 --- a/lib/src/webview_manager.dart +++ b/lib/src/webview_manager.dart @@ -17,9 +17,10 @@ class WebviewManager extends ValueNotifier { final MethodChannel pluginChannel = const MethodChannel("webview_cef"); final Map _webViews = {}; + final Map _injectUserScripts = {}; final Map _tempWebViews = {}; - InjectUserScripts? _injectUserScripts = InjectUserScripts(); + final Map _tempInjectUserScripts = {}; int nextIndex = 1; @@ -33,7 +34,7 @@ class WebviewManager extends ValueNotifier { final controller = WebViewController(pluginChannel, browserIndex, loading: loading); _tempWebViews[browserIndex] = controller; - _injectUserScripts = injectUserScripts; + _tempInjectUserScripts[browserIndex] = injectUserScripts; return controller; } @@ -74,7 +75,10 @@ class WebviewManager extends ValueNotifier { void onBrowserCreated(int browserIndex, int browserId) { _webViews[browserId] = _tempWebViews[browserIndex]!; + _injectUserScripts[browserId] = _tempInjectUserScripts[browserIndex]; + _tempWebViews.remove(browserIndex); + _tempInjectUserScripts.remove(browserIndex); } Future methodCallhandler(MethodCall call) async { @@ -134,7 +138,7 @@ class WebviewManager extends ValueNotifier { int browserId = call.arguments["browserId"] as int; String urlId = call.arguments["urlId"] as String; - await _injectUserScriptIfNeeds(browserId, _injectUserScripts?.retrieveLoadStartInjectScripts() ?? []); + await _injectUserScriptIfNeeds(browserId, _injectUserScripts[browserId]?.retrieveLoadStartInjectScripts() ?? []); WebViewController controller = _webViews[browserId] as WebViewController; @@ -144,7 +148,7 @@ class WebviewManager extends ValueNotifier { int browserId = call.arguments["browserId"] as int; String urlId = call.arguments["urlId"] as String; - await _injectUserScriptIfNeeds(browserId, _injectUserScripts?.retrieveLoadEndInjectScripts() ?? []); + await _injectUserScriptIfNeeds(browserId, _injectUserScripts[browserId]?.retrieveLoadEndInjectScripts() ?? []); WebViewController controller = _webViews[browserId] as WebViewController;