1

I'm getting the following error when running my hyrbrid-remote app in the Android Emulator. Everything works fine in iOS. All of my resources are static resources in SF.

07-24 09:53:51.017: I/chromium(4474): [INFO:CONSOLE(0)] "XMLHttpRequest cannot load https://cs10.salesforce.com/!gap_exec?1406210030920. 
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'https://c.cs10.visual.force.com' is therefore not allowed access.",
source: https://c.cs10.visual.force.com/apex/MobileLanding (0)

Any suggestions?

Also, if its helpful I'm using SmartStore as well.

EDIT:

I found this in /Smartstore/res/xml/config.xml could this be part of the issue?

 <access origin="http://127.0.0.1*"/> <!-- allow local pages -->
 <access origin="https://force.com" subdomains="true" />
 <access origin="https://salesforce.com" subdomains="true" />

EDIT 2:

I found this line inside the cordova.js file which I believe is the static resource that causes the error. This gap_exec is what the the error is complaining about.

        execXhr.open('HEAD', "/!gap_exec?" + (+new Date()), true);
        if (!vcHeaderValue) {
            vcHeaderValue = /.*\((.*)\)/.exec(navigator.userAgent)[1];
        }
        execXhr.setRequestHeader('vc', vcHeaderValue);
        execXhr.setRequestHeader('rc', ++requestCount);
        if (shouldBundleCommandJson()) {
            execXhr.setRequestHeader('cmds', iOSExec.nativeFetchMessages());
        }
        execXhr.send(null);
4

I've seen this earlier. This can happen on emulator when your hybrid app is invoking Visualforce pages and the root cause is same as when you'd see this issue in a web application. This thread explains the issue and the solution.

In most cases, the culprit would be the requestData parameter. If you do not need it, remove it. Also, you can use add a remote site setting and then use sforce.connection.remoteFunction to overcome this issue.

This issue will/ should NOT happen on a real device though and it should work.

1

This may be due to the server not register these headers.

But for android you can make as patch for api 16 and greater... Find the following code:

if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN){ 
  webview.getSettings().setAllowUniversalAccessFromFileURLs(true);
}

Hope it will work for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.