Open bi-samson opened 4 years ago
Default user agent for WebView class on android (Emulator?) like Mozilla/5.0 (Linux; Android 8.1.0; Android SDK built for x86 Build/OSM 1180201026 ; wv) AppleWebkit/537.36 (KHTML, 11ke Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36
. But some web pages (include BI, GIZ) could not display correct layout.
It works as I expected when the following changes.
- Mozilla/5.0 (Linux; Android 8.1.0; Android SDK built for x86 Build/OSM 1180201026 ; wv) AppleWebkit/537.36 (KHTML, 11ke Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36
+ Mozilla/5.0 (Linux; Android 8.1.0; XXXXXXX SDK built for x86 Build/OSM 1180201026 ; wv) AppleWebkit/537.36 (KHTML, 11ke Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36
Thank you Thank you! So I add this line of code somewhere?
I tried adding this in webview and it didn't work.
userAgent: "random",
You can try it.
diff --git a/lib/webview_container.dart b/lib/webview_container.dart
index bc03a77..f8d6287 100644
--- a/lib/webview_container.dart
+++ b/lib/webview_container.dart
@@ -22,7 +22,7 @@ class _WebViewContainerState extends State<WebViewContainer> {
child: WebView(
key: _key,
javascriptMode: JavascriptMode.unrestricted,
- userAgent: "random",
+ userAgent: "Mozilla/5.0 (Linux; Android 8.1.0; XXXXXXX SDK built for x86 Build/OSM 1180201026 ; wv) AppleWebkit/537.36 (KHTML
, 11ke Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36",
initialUrl: _url))
],
I think it would be better to fix that the parser for UserAgent on the server side.
However, this behavior occurs only on the emulator and not on the actual devices, so I think it can be ignored.
Thank you thank you! I had only tried it on the emulator and never tried on an actual device yet. Thank you!
Problem: Webpage loaded into webview is too big to fit mobile phone screen. I imagine I will need to load the mobile version of the page but I don't know how.
Some sites becomes too big, some sites the layout breaks and sites that are responsive are completely fine.
Tried adding userAgent: "random",
in WebView but didn't work.
webview_flutter: ^0.3.21 dependencies added to pubspec.yaml and added this to the end of info.plist
Here is code within webview_container.dart