Android Question Can't change Webview to Desktop mode

kps

Member
Hello all,
I have gone through these threads on this topic.
https://www.b4x.com/android/forum/threads/view-the-desktop-version-of-a-site-with-webview.108361/
https://www.b4x.com/android/forum/threads/webview-desktop-mode-problem.85401/#post-541491

This one doesn't seem to exist any more.
http://www.useragentstring.com/pages/Android Webkit Browser/

From Stackoverflow
https://stackoverflow.com/questions...view-to-view-desktop-site-and-not-mobile-site

I tried this code with various useragent strings
B4A:
    Dim wv As WebViewSettings
    
    Log(wv.getUserAgentString(WebView1))
    'This is the Log output
    'Mozilla/5.0 (Linux; Android 7.0; Redmi Note 4 Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/84.0.4147.111 Mobile Safari/537.36

    wv.setUseWideViewPort(WebView1,True)
    wv.setLoadWithOverviewMode(WebView1,True)
    WebView1.JavaScriptEnabled=True
    wv.setSupportZoom(WebView1,True)
    
    'wv.setUserAgentString(WebView1,"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0")
    'wv.setUserAgentString(WebView1,"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Safari/530.17")
    'wv.setUserAgentString(WebView1,"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0")
    'wv.setUserAgentString(WebView1,"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0")
    'wv.setUserAgentString(WebView1,"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50")
    'wv.setUserAgentString(WebView1,"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36")
    'wv.setUserAgentString(WebView1,"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1")
    'wv.setUserAgentString(WebView1,"Mozilla/5.0 (Linux; U; Android 2.1-update1; de-de; HTC Desire 1.19.161.5 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17")
    'wv.setUserAgentString(WebView1,"")
    wv.setUserAgentString(WebView1,"Mozilla/5.0")
    
    WebView1.LoadUrl("http://trichyayyappan.com")

None of them worked.
This site shows a huge popup; you can't see the X button to kill it.

In Chrome browser, you can change to Desktop site mode and kill it.

Any suggestions ?

Regards,
KPS
 

JohnC

Expert
Licensed User
Longtime User
Setup the chrome browser to the mode that allows the "X" to be shown, then use chrome to navigate to this web service to see what the useragent string is that the chrome browser is sending:


So you can duplicate it with webview.

Then after you configure webview to send it, first just double-check to make sure that webview is in fact now sending the proper useragent string by forcing webview to also navigate to the above web service and verify that the reported useragent is in fact correct.
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
You can also try setting the webview to Overview mode using WebviewSettings:
B4X:
wvs.setLoadWithOverviewMode(wv,True)

Or setting initial zoom to "far" using Webviewsettings:
B4X:
wvs.setDefaultZoom(wv,"FAR")

Maybe one of these will zoom the page out enough to see the "X".
 
Upvote 0

kps

Member
@JohnC
Your idea of getting the useragent string was sheer genius !
Since I was able to get the desktop mode on firebox browser also (in the device which I am using for testing this app), I was supremely confident that I could nail this issue with this method.
But sadly disappointed.

To start with, the url referred by you declined to open with this message.
Your request was blocked.
Sorry, we get too much bot/crawler traffic from hosting companies so now we just block it outright. Our API provides you all the same information and makes it easier for you, instead of having to scrape the HTML.

Now that the approach was clear, I got an alternate site which gives you the useragent.
http://whatsmyuseragent.com
It automatically redirects to
https://www.whoishostingthis.com/tools/user-agent/
and gave my useragent as
Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0

Yes, I got this string accessing this site from the same device, using firefox browser, set to Desktop mode.
Then I set this string in my webview and tried hoping that the issue would be nailed. It was not.

Then, as suggested by you, I cross verified accessing the "whatsmyuseragent" site in webview and got the same useragent string report. So, the issue is getting a little mysterious. Why does the problem remain in spite of my webview using the same useragent string as done by firefox browser?

Then, I went on to the second suggestion. I wasn't very hopeful since I have experimented enough with this Zoom and Font settings of WebviewSettings for another app of mine and I could never get it working. No matter what setting I use, the zoom level is always the same.

This time also, it didn't make any difference.
I wonder if anybody has ever achieved any success with the Font and Zoom settings of WebviewSettings.

Issue still remains hanging.
Sorry for the late response. Timezone problem. I am on the other side of the globe

Regards,
KPS
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

kps

Member
@JohnC

This might be a silly question, but did you remember to add the chromeclient to the webview?

Not at all. I wasn't even aware of that. I am just making a beginning with B4A and android, you see !

But the sad part is, even after adding that there is no change in situation.

Obviously, I am doing some elementary mistake and I have no idea what is that.
I made a separate project just for testing the webview's desktop mode. Here is the code.
B4A:
ub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private WebView1 As WebView
    Dim wve As WebViewExtras
    Dim wvs As WebViewSettings
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    wve.addWebChromeClient(WebView1, "WVE")
    wvs.setLoadWithOverviewMode(WebView1, True)
    wvs.setDefaultZoom(WebView1,"FAR")
    
    'chrome browser -mobile mode
    'wvs.setUserAgentString(WebView1,"Mozilla/5.0 (Linux; Android 7.0; Redmi Note 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.111 Mobile Safari/537.36")
    
    'chrome browser -desktop mode
    wvs.setUserAgentString(WebView1, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.111 Safari/537.36")
    
    WebView1.LoadUrl("http://trichyayyappan.com")
End Sub

The behaviour is the same with any other URL also.
I can't get the desktop mode at all.

Regards,
KPS
 
Upvote 0

kps

Member
Some additional observations..

So far, I was testing on Redmi Note 4.

I switched over to Xiomi Mi A1
With everything remaining same, the page was not even loading.
Web page not available
The web page at http://trichyayyappan.com/swamy/ could not be loaded because:

net::ERR_CLEARTEXT_NOT_PERMITTED

Then I searched for this error and found this thread.
https://www.b4x.com/android/forum/t...ed-by-network-security-policy.119569/#content

Added the statement in manifest
CreateResourceFromFile(Macro, Core.NetworkClearText)

The error message went away and the behaviour is similar to my Note 4.

All this is somewhat disconcerting.
I feel I am always groping in the dark unsure of what I am doing and what results I can expect.

It is so embarrassing to keep disturbing others and asking for help.
I never had this problem/feeling with Legacy Visual Basic. Everything was so very well documented.

Regards
KPS
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
From inside the IDE, select "File...Export as ZIP" and post the zip.

I might be able to take a deeper look at your code in a few days.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…