fix: webview

This commit is contained in:
xkeyC
2025-12-13 15:56:52 +08:00
parent f68b7a4380
commit a132c85b8c
4 changed files with 327 additions and 95 deletions

View File

@@ -71,8 +71,11 @@ class WebViewModel {
height: loginMode ? 720 : 1080,
userDataFolder: "$applicationSupportDir/webview_data",
enableDevtools: kDebugMode,
userAgent:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0",
);
webview.addOnNavigationCallback(_onNavigation);
// 添加导航完成回调(用于注入脚本)
webview.addOnNavigationCompletedCallback(_onNavigationCompleted);
@@ -104,12 +107,6 @@ class WebViewModel {
dPrint("Navigation completed: $newUrl");
url = newUrl;
// 在页面加载时注入拦截器
if (requestInterceptorScript.isNotEmpty) {
dPrint("Injecting request interceptor for: $url");
webview.executeScript(requestInterceptorScript);
}
if (localizationResource.isEmpty) return;
dPrint("webview Navigating url === $url");
@@ -285,10 +282,19 @@ class WebViewModel {
FutureOr<void> dispose() {
webview.removeOnNavigationCompletedCallback(_onNavigationCompleted);
webview.removeOnNavigationCallback(_onNavigation);
if (loginMode && !_loginModeSuccess) {
loginCallback?.call(null, false);
}
_isClosed = true;
webview.dispose();
}
void _onNavigation(String url) {
// 在页面加载时注入拦截器
if (requestInterceptorScript.isNotEmpty) {
dPrint("Injecting request interceptor for: $url");
webview.executeScript(requestInterceptorScript);
}
}
}