-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[webview_flutter] get/set a custom User Agent #1920
Changes from 10 commits
953e220
9478588
45e915d
ae81a98
de27c90
cbcc808
4141cf2
d54e0bc
86d44ca
7959989
7b26a41
7fed032
c5cc6a7
c99c8f2
c931307
7976151
4c0d2f3
de4d1df
5be86ef
5887b33
bf8b74c
ebe699d
ee693fd
641537b
db3cfb9
974c16e
c13245a
3282117
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,11 @@ class MethodChannelWebViewPlatform implements WebViewPlatformController { | |
| 'removeJavascriptChannels', javascriptChannelNames.toList()); | ||
| } | ||
|
|
||
| @override | ||
| Future<String> getUserAgent() { | ||
| return _channel.invokeMethod('getUserAgent'); | ||
| } | ||
|
|
||
| /// Method channel mplementation for [WebViewPlatform.clearCookies]. | ||
| static Future<bool> clearCookies() { | ||
| return _cookieManagerChannel | ||
|
|
@@ -122,6 +127,7 @@ class MethodChannelWebViewPlatform implements WebViewPlatformController { | |
| _addIfNonNull('jsMode', settings.javascriptMode?.index); | ||
| _addIfNonNull('hasNavigationDelegate', settings.hasNavigationDelegate); | ||
| _addIfNonNull('debuggingEnabled', settings.debuggingEnabled); | ||
| _addIfNonNull('userAgent', settings.userAgent); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if we rebuild a WebView that had an explicitly set We should add an test for this scenario as well (build with an explicitly set user agent, rebuild with user agent set to null)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. I changed it so that the user agent can be set to null and the default platform user agent is used after a rebuild. Additionally I adapted the same logic for the FakePlatformWebView unit tests.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I pushed 7976151 with a proposal on how to do that, let me know whether that makes sense to you.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that is a nice way to handle nullable settings and I agree that updating the user agent every rebuild is unnecessary. |
||
| return map; | ||
| } | ||
|
|
||
|
|
@@ -135,6 +141,7 @@ class MethodChannelWebViewPlatform implements WebViewPlatformController { | |
| 'initialUrl': creationParams.initialUrl, | ||
| 'settings': _webSettingsToMap(creationParams.webSettings), | ||
| 'javascriptChannelNames': creationParams.javascriptChannelNames.toList(), | ||
| 'userAgent': creationParams.userAgent, | ||
| }; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.