Я пытаюсь отправить файл cookie на мою страницу веб-просмотра Flutter. Итак, я установил webview_flutter: ^ 1.0.7 и использую вот так:
@override
void initState() {
super.initState();
_controller.future.then((controller) async {
wvc = controller;
Map<String, String> header = {};
// 1 :
wvc.evaluateJavascript('document.cookie="SESSION-Test=token";');
wvc.loadUrl("https://webmobile.parsian-bank.ir/WebView/CoTest.html");
// 2 :
// header = {"SESSION": "12343254"};
// wvc.loadUrl("https://webmobile.parsian-bank.ir/WebView/CoTest.html",
// headers: header);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: WebView(
initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy.always_allow,
debuggingEnabled: true,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (webViewController) async {
_controller.complete(webViewController);
},
onPageFinished: (val) async {
String cookies = await wvc.evaluateJavascript('document.cookie');
print("---> cookie is $cookies");
},
)),
);
}
}
CoTest.html имеет простой код:
<!DOCTYPE html>
<html dir="rtl" lang="fa-IR" "=""><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><style class="vjs-styles-defaults">
.video-js {
width: 300px;
height: 150px;
}
.vjs-fluid {
padding-top: 56.25%
}
</style>
</head>
<body>
<script>
document.write( "cookies are === >>>>>> " + document.cookie + " <<<<<<");
</script>cookies are === >>>>>> <<<<<<
</body></html>
Но когда я пытаюсь показать страницу, у меня возникают эти ошибки, и я просто получаю пустой экран:
E/chromium( 6140): [ERROR:ssl_client_socket_impl.cc(946)] handshake failed; returned -1, SSL error code 1, net_error -202
I/chromium( 6140): [INFO:CONSOLE(1)] "Uncaught SecurityError: Failed to read the 'cookie' property from 'Document': Access is denied for this document.",
Это основной манифест:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testt">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="testt"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
Обновление:
Проблема с Cookie-менеджером работает на IOS 11+.