Search code examples
ionic-frameworkuser-agentcapacitor

Ionic: unable to appendUserAgent


I have an android/ios application with ionic+capacitor. Capacitor version is v5. I want append a custom string to the useragent, but nothing worked.

Here is my config file:

        /// <reference types="@capacitor/push-notifications" />
/// <reference types="@capacitor/splash-screen" />

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
    appId: 'io.icoders.jobinfo',
    appName: 'Jobinfo',
    webDir: 'dist',
    plugins: {
        SplashScreen: {
            launchShowDuration: 5000,
            launchAutoHide: true,
            backgroundColor: '#ffffffff',
            androidSplashResourceName: 'splash',
            androidScaleType: 'CENTER_CROP',
            showSpinner: true,
            androidSpinnerStyle: 'large',
            iosSpinnerStyle: 'small',
            spinnerColor: '#999999',
            splashFullScreen: true,
            splashImmersive: false,
            layoutName: 'launch_screen',
            useDialog: false
        }
    },
    appendUserAgent: 'JobinfoApp',
    overrideUserAgent: 'JobinfoApp',
    android: {
        appendUserAgent: 'JobinfoApp',
        overrideUserAgent: 'JobinfoApp',
    },
    ios: {
        appendUserAgent: 'JobinfoApp',
        overrideUserAgent: 'JobinfoApp',
    }
};

export default config;

I already tried the "appendUserAgent" config in ios and android tag, also in the main body, not working, the useragent is restored the original. What is the problem?


Solution

  • Here is a solution that worked for me, but remember that you can only test it from the emulator, on the browser use Chrome to test it by using the "chrome://inspect"

    import { CapacitorConfig } from '@capacitor/cli';
    
     appendUserAgent: 'appId=app.jobinfo',