Software Archive
Read-only legacy content
17061 Discussions

Change user Agent in config

Isaiah_L_
Beginner
1,368 Views

Hi folks, can anyone please describe how i would be able to change the user agent, outside of my js code, that is in the configuration file. How exactly would i do that.

0 Kudos
13 Replies
PaulF_IntelCorp
Employee
1,368 Views

Not sure what "user agent" you are referring to. What are you trying to accomplish?

0 Kudos
Isaiah_L_
Beginner
1,368 Views

Well i mean the browser, so the webkit browser. I have a php server taking input, from my app but i want to know if someone is trying to access the server from their, desktop, on chrome, firefox, ie, to send wrong data (cheaters) or just their regular phone tablet browser and take note of it. I know its not full proof to avoid cheaters but with some of the other deturrents in place this will help.

Soin other words i want to change the user agent of the browser in my app to xyyz or whatever so that when my app connects to the server my server can check and say is this, chrome, firefox, webkit etc, and take appropriate action.

 

0 Kudos
Isaiah_L_
Beginner
1,368 Views

I tried

<preference name="OverrideUserAgent" value="MyCordovaApp/1.2.3" />

but it didnt seem to work...

Also I don't want to use something like this

https://github.com/LouisT/cordova-useragent

Because I don't want the call to appear in my javascript.

also see the last two bullet points on this page regarding this...

http://cordova.apache.org/docs/en/5.1.1/guide/platforms/android/config.html

0 Kudos
PaulF_IntelCorp
Employee
1,368 Views

Did you put that preference in the intelxdk.config.additions.xml file? That's where it needs to go...

0 Kudos
Isaiah_L_
Beginner
1,368 Views

Yes thats where I put it but it still says the same thing. I will post my code and the compile log when I get home today.

0 Kudos
Isaiah_L_
Beginner
1,368 Views
Update:
Im using <preference name="OverrideUserAgent" value="MyCordovaApp/1.2.3" /> in my intelxdk.config.additions.xml

I just thought I'd try this, and when I compile in just "Android" build it works perfectly... but unfortunately I am not building with plain cordova webview I need to use the crosswalk webview.... Have any idea why it works on "Android" build but not on "Crosswalk for Android"?

0 Kudos
PaulF_IntelCorp
Employee
1,368 Views

Make sure you're using CLI 5.1.1 for your build system to make that work. It won't work with the CLI 4.1.2 Crosswalk builders due to the way Crosswalk is built in that system. However, even with that, it might not work with Crosswalk because Crosswalk replaces the native webview, and the mechanism you're using might get overwritten by the Crosswalk webview... I don't know how that preference works, so you'll have to do some experimenting.

0 Kudos
Isaiah_L_
Beginner
1,368 Views

Hi Paul, thank again for all the replies, I've been racking my brains over this and tried many different ways to no avail.

Do you think that I can do something like this...?

<intelxdk:crosswalk xwalk-command-line="--disable-pull-to-refresh-effect" />

but instead of --disable-pull-to-refresh-effect

Something like "--set-user-agent foobar"

<intelxdk:crosswalk xwalk-command-line="--set-user-agent MyUserAgent" />

Would your devs know about that, and if that would work, is there a list of xwalk commands somewhere that I can reference, because I couldn't find anything on crosswalk-project.org. In other words I'm asking if i can set the user agent via the crosswalk command line within the intelxdk because crosswalk seems to be overwriting the cordova webview user agent with it's own as you mentioned but then it's not allowing me to edit it.

0 Kudos
PaulF_IntelCorp
Employee
1,368 Views

I would try this:

<intelxdk:crosswalk xwalk-command-line="--user-agent MyUserAgentString" />

See this list of Chromium command-line options > http://peter.sh/experiments/chromium-command-line-switches/#user-agent

0 Kudos
Isaiah_L_
Beginner
1,368 Views

Woe is me... I have literally tried every combination of this and nothing seems to work... (excuse me while I go jump off a bridge...)

I have tried...

<intelxdk:crosswalk xwalk-command-line="--user-agent MyUserAgentString" />

<intelxdk:crosswalk xwalk-command-line="--user-agent=MyUserAgentString" />

<intelxdk:crosswalk xwalk-command-line="--user-agent='MyUserAgentString'" />

<intelxdk:crosswalk xwalk-command-line="--user-agent = MyUserAgentString" />

and just about every other variation that I can think of to no avail... I'm at a wall!

I might add that when I add other calls to the command line like...

<intelxdk:crosswalk xwalk-command-line="--show-fps-counter" />  they work fine, So it's not that I'm as dumb as a rock, user-agent just isn't working for some reason... :((

0 Kudos
Isaiah_L_
Beginner
1,368 Views

Hi again Paul, do you think the Devs would know why this isn't working?

0 Kudos
PaulF_IntelCorp
Employee
1,368 Views

My suspicion is that it "works" but that the Crosswalk library is overwriting it because they modify the userAgent string to include the Crosswalk version number (e.g., "... Crosswalk/15.44.384.13 ..."). We only provide a way to include the Crosswalk library as part of your build, we don't actually own that project (it's an open source project). I think your best bet would be to file a Jira with the Crosswalk project letting them know that this does not work. Unfortunately, they will only fix it in the next version, so it will be a while before you would see it coming through the XDK...

BTW, there's no guarantee that EVERY option in that Chromium command-line option works with Crosswalk, because there's no guidance in that list regarding which versions of Chromium support which versions of the the command-line switches... :(

Another thought, you may not want to use the command-line option, anyway, because you said you didn't want the replacement userAgent string in your JavaScript (I assume because you want to hide it). Every command-line option you add gets put inside a clear text file in the app package, so that's fairly easy to inspect if you have a copy of the APK, so this approach may not meet your needs. In which case you might want to make the request to the Crosswalk team (via their Jira system) to be one that honors the original approach you were taking, using the config.xml preference option.

Or, make a custom version of that plugin you found, and hide the agent string inside the Java part of that plugin... You could then add your custom variant of that plugin as a "local" plugin into your project.

0 Kudos
Isaiah_L_
Beginner
1,368 Views

Thnks Paul, yes you're right, they are in plain text just sitting there...

I was frustrated that i wasted four days on this but then i accidentally read one of your post about something else and realized that my gpu acceleration was actually off, i changed the settings to turn it on and now my app is blazing fast... no lag at all, if i wasnt searching for a solution to this problem i would have never stumbled upon this even bigger issue that i didnt even realized existed. So thank you!

So i will go with your suggestions regarding useragent but to tell the truth, it all seems insignificant now in retrospect... now that my app feels like king kong's fist. :))

0 Kudos
Reply