CORS not working properly when Chrome started with Appium

Software versions

Appium: 1.6.3
Chromedriver: 2.26.436421 & 2.25.426935
Android API version: 23, 24, 25 (with Google APIs)
Real device/emulator: emulator
OS version: MacOS X El Capitan 10.11.6

The issue briefly
I’m trying to automate push notifications tests for a website, but without success. If I execute the test scenario manually all works nicely, the device is registered in the service we use (PushWoosh), and it receives notifications, when appropriate actions are triggered. But when I run the automatic test on the emulator, the device is never registered as the call to PushWoosh is never made.

Test scenario is simple: open a page, register new user, accept push notifications via native dialog, logout.

The biggest (only?) difference between manual and automatic execution seems to be the way in which the browser is started. In the former I start it manually, in the latter it is started by Appium.

Now, apart from the failure to register the device also a banner we load via an iframe from a different domain fails to load as well (but it loads nicely if I start Chrome manually). I’m thinking, that for reasons unknown to me, CORS (cross-origin resource sharing) in Chrome launched by Appium does not work the same way as in a version launched manually.

Any way around it?

What have I tried?

  • use ChromeOptions (--disable-web-security, --allow-file-access-from-files, --user-data-dir=/tmp/chrome, --allow-cross-origin-auth-prompt, --allow-file-access)
  • use Allow-Control-Allow-Origin: * extension (extensions are not supported on mobile Chrome, right?)
  • install Chrome (different versions) manually via adb install <apk> instead of using one supplied by Google

In all cases Google Play Services are present, so missing GCM is not a problem (not sure if all push notifications for Android depend on it, but the service we use certainly does).

When Chrome is started with requested ChromeOptions I can see in Appium log that it is indeed requesting a browser, with these options set in desiredCapabilities, but I see no effect of these settings:

[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"newCommandTimeout":1800,"automationName":"APPIUM","browserName":"Chrome","chromeOptions":{"args":["--ignore-ssl-errors","--disable-web-security","--ignore-certificate-errors","--allow-file-access-from-files","--allow-file-access","--allow-cross-origin-auth-prompt","--user-data-dir=/tmp/chrome_dev"],"extensions":[]},"platformName":"Android","deviceName":"Nexus 5X API 25 x86","deviceReadyTimeout":1800},{},{"desiredCapabilities":{"newCommandTimeout":1800,"automationName":"APPIUM","browserName":"Chrome","chromeOptions":{"args":["--ignore-ssl-errors","--disable-web-security","--ignore-certificate-errors","--allow-file-access-from-files","--allow-file-access","--allow-cross-origin-auth-prompt","--user-data-dir=/tmp/chrome_dev"],"extensions":[]},"platformName":"Android","deviceName":"Nexus 5X API 25 x86","deviceReadyTimeout":1800},"requiredCapabilities":{}},null,null]

Any way to see if they were really used when starting Chrome?

How do I start the driver?
This will not be a complete code, but more or less, that’s how it looks:

public class AndroidChromeCapability extends ABrowserCapability {
    @Override protected void setupCapabilities() {
        capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "ANDROID");
        capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus 5X API 25 x86");
        capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "APPIUM");
        capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 1800);
        capabilities.setCapability(MobileCapabilityType.DEVICE_READY_TIMEOUT, 1800);

        ChromeOptions options = new ChromeOptions();
        options.addArguments("--disable-extensions");
        options.addArguments("--test-type");
        options.addArguments("--disable-popup-blocking");
        options.addArguments("--ignore-ssl-errors");
        options.addArguments("--dns-prefetch-disable");
        options.addArguments("--disable-web-security");
        options.addArguments("--allow-file-access-from-files");

        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    }
}

...
ABrowserCapability browserCapability = capabilityFactory.getCapabilityFor(browser);
DesiredCapabilities capabilities = browserCapability.getCapabilities();
...
RemoteWebDriver driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
...
return driver;

What do I need?
I’m kind of stuck here and really any help would be appreciated. What else should I check? Device log (accessed via adb logcat) is not of much help, can’t use desktop Chrome remote device debugger as it cannot connect to an emulated device, so I do not have more ideas as where else to look for a solution…

Maybe I’m doing something obviously wrong, but fail to notice it?