Search code examples
androidandroid-webviewuser-agent

Set user-agent in WebView for Android, API 30


After reading android user agent I set in WebView:

webView.settings.apply {
    userAgentString = "some string"
    javaScriptEnabled = true
    javaScriptCanOpenWindowsAutomatically = true
    domStorageEnabled = true
}

And loaded the URL "https://www.whoishostingthis.com/tools/user-agent/". In emulators of API 21 and 29 it worked right. But in API 30 it showed:

enter image description here

How to change user-agent in API 30?


Solution

  • According to https://www.infoq.com/news/2020/03/chrome-phasing-user-agent/, Chrome will replace User-Agent with a new API called Client Hints.