cordova-plugin-inappbrowser icon indicating copy to clipboard operation
cordova-plugin-inappbrowser copied to clipboard

OverrideUserAgent and AppendUserAgent not working for Android

Open ajay1271 opened this issue 5 years ago • 11 comments

Bug Report

Problem

Tried changing the webview UserAgent in config.xml. used both

<preference name="OverrideUserAgent" value="Mozilla/5.0 Google" />
<preference name="AppendUserAgent" value="Mozilla/5.0 Google" /> 

in config.xml for both android and iOS preferences. Its working fine for iOS but not working for android.

What is expected to happen?

it should should change the userAgent to given OverrideUserAgent value

What does actually happen?

Its not changing for android.

Information

Tried debugging the generated code. Its giving null values for both OverrideUserAgent and AppendUserAgent preferences in SystemWebViewEngine.Java class

Command or Code

**config.xml**

<?xml version='1.0' encoding='utf-8'?>
<widget id="xxxxxx" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"
android-versionCode="xxxxxx" version="xxxxxx">
  <name>xxxxxx</name>
  <description>
    xxxxxx
  </description>
  <author email="xxxxxx" href="xxxxxx">
  xxxxxx
  </author>
  <content src="index.html" />
  <access origin="*" />
  <allow-navigation href="*" />
  <allow-intent href="http://*/*" />
  <allow-intent href="https://*/*" />
  <allow-intent href="tel:*" />
  <allow-intent href="sms:*" />
  <allow-intent href="mailto:*" />
  <allow-intent href="geo:*" />
  <platform name="android">
    <allow-intent href="market:*" />   
    <preference name="OverrideUserAgent" value="Mozilla/5.0 Google" />
    <preference name="android-targetSdkVersion" value="29" />
  </platform>
  <platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
    <preference name="orientation" value="portrait" />
    <preference name="StatusBarOverlaysWebView" value="false" />
    <preference name="StatusBarBackgroundColor" value="#cc0033" />
    <preference name="WKWebViewOnly" value="true" />
    <feature name="CDVWKWebViewEngine">
        <param name="ios-package" value="CDVWKWebViewEngine" />
    </feature>
    <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
    <preference name="OverrideUserAgent" value="Mozilla/5.0 Google" />
  </platform>
  
  <plugin name="cordova-plugin-keyboard" spec="^1.1.5" />
  <plugin name="cordova-plugin-statusbar" spec="^2.3.0" />
  <plugin name="cordova-plugin-whitelist" spec="1" />
  <plugin name="cordova-plugin-customurlscheme" spec="^4.3.0">
    <variable name="URL_SCHEME" value="xxxxios" />
  </plugin>
  <plugin name="cordova-plugin-fastclick" spec="https://github.com/chemerisuk/cordova-plugin-fastclick.git" />
  <engine name="ios" spec="~4.5.4" />
</widget>

Environment, Platform, Device

Android

Version information

Android targeted SDK 29

[email protected] cordova-plugin-inappbrowser 4.0.0

platforms list: [email protected] [email protected]

Checklist

  • [x] I searched for existing GitHub issues
  • [x] I updated all Cordova tooling to most recent version
  • [x] I included all the necessary information above

ajay1271 avatar Aug 12 '20 18:08 ajay1271

Based on https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/ConfigXmlParser.java

I don't think android supports having preferences inside the <platform> tags... Which I think is problematic. But does it work if you move the preference outside of the <platform> tags?

breautek avatar Aug 12 '20 18:08 breautek

Based on https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/ConfigXmlParser.java

I don't think android supports having preferences inside the <platform> tags... Which I think is problematic. But does it work if you move the preference outside of the <platform> tags?

Hi, thanks for the reply. I tried moving the appendUserAgent preference outside the platform tag. Still the same issue

ajay1271 avatar Aug 12 '20 18:08 ajay1271

Both of these properties works for me on cordova-android@9 inside and outside the <platform> tag, can you try upgrading the platform?

If it still fails for you on cordova-android@9, then we will need a minimal reproducible example app.

breautek avatar Aug 12 '20 22:08 breautek

I too am having this same issue with "cordova-android": "^9.0.0".

Everything works as expected on iOS devices and on my Kindle Fire. Although on a device where our MDM is forcing Chrome Engine for the webkit it is not working. Could that be the issue?

shawnmbradley avatar Sep 30 '20 15:09 shawnmbradley

Same issue with cordova-android 9.0. On iOS works perfectly, but on Android works the very first time I open the inAppBrowser. Afterwards I need to reinstall the app to work again. I too have the AppendUserAgent property outside platform tags.

MateiNenciu avatar Oct 14 '20 11:10 MateiNenciu

Same bug. Not working.

Either Emulator with "Dalvik/2.1.0 (Linux; U; Android 10; Android SDK built for x86 Build/QSR1.190920.001)" or real device with "Dalvik/2.1.0 (Linux; U; Android 8.0.0; PRA-LX1 Build/HUAWEIPRA-LX1)"

laurentperez avatar Nov 23 '20 19:11 laurentperez

Same bug. ios - work android - bug

Cordova Android 11.0.0

harlamoff avatar Nov 10 '22 12:11 harlamoff