Android Question Weird User Agent Behaviour

schalkgreyling

Member
Licensed User
Longtime User
Good day all,

I have quite an interesting issue which i've been struggling with for a few weeks now. I wrote an application that interacts with a website using JavaScript injection. The website is not owned by me so unfortunately I cannot directly access the DB or change the website code.

So the issue(or lets start with the process):

As I create the Webview, i change the user agent to the mobile one, which works. Now from what i see, it looks like the server is load balanced, sending different clients to (2) different servers depending on their login credentials.

When most users log in, the process works, and the Javascript injection finds place because the app has been coded to work with the mobile site.

When using the same URL with a different login name, the user ends up in the desktop version of the app and the javascript injections does not work.

I'm pretty sure the mobile useragent is being sent as when I remove this line of code, both users find the dekstop view and not the mobile.

The Problem:

The Javascript injections only works on the mobile site- using webview, when using JS injection with Chrome(desktop) it works with the desktop site as well, but not with b4a, Android studio or B4i webviews:/

When using the Chrome(on android) all login credentials sends me to the mobile version of the website, and not the desktop.

The webview on b4a send me to the desktop site for some of the users(So i am assuming Chrome has something else regarding the user agent which webview does not.)

If anyone has an idea how to force the useragent besides the code belowe, please help :)

I Have tried many different Agent Strings, all behaving the same way with some users receiving the desktop view, the same happening on B4i.

Obj1.Target = WebView1
Obj1.Target = Obj1.RunMethod("getSettings")
Obj1.RunMethod2("setUserAgentString", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7", "java.lang.String")

If anyone is willing to help, please let me know so that I can share some more info details- as the project contains sensitive info.
 

schalkgreyling

Member
Licensed User
Longtime User
Will it be difficult to support both the desktop site and the mobile site?
In terms of Code not at all. The issue is that the JS injection doesn't seem to work on webview(for desktop). But when I use JS injection on my laptop with the same page it works which is why im requesting the mobile site :/
 
Last edited:
Upvote 0
Top