Skip to content

OverrideUserAgent and AppendUserAgent not working for Android #759

@ajay1271

Description

@ajay1271

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions