Is it possible to set custom useragent in webview?


#1

Hi All,

Is there a way to set custom useragent for webview ?
If so can someone please guide me how to set it.

Thanks in advance.


#2

You could try the nativescript-webview-utils plugin to add a custom header. Here’s some sample code: https://github.com/EddyVerbruggen/nativescript-webview-utils/blob/906c65878f431c61c09fc343b4c1a5fb0b9599c8/demo/app/main-page.ts#L22-L25


#3

Thank you Eddy for your response.
I did override the “User-Agent” header but some how it is still taking the default User-Agent of android web view.
I have added some new custom headers and the header are setting successfully but i didn’t got success with the User-Agent header :pensive:.


#4

Finally i was able to set custom User-Agent :grinning:.
Used following code to do so.

WebView.android.getSettings().setUserAgentString(“your-custom-user-agent”);


#5

Any way to set user agent for iOS (instead of WebView.android) is there some equivalent for iOS?


#6

Yes there is, and you can now use this plugin function to do so: https://github.com/EddyVerbruggen/nativescript-webview-utils#setuseragent


#7

Thanks so much for making that @Eddy! works great.