0

I have been using Ripple Emulator for some time, but after reinstalling it is no longer using the XHR CORS proxy when requesting cross domain resources.

I have tried the suggested test code in: Internet not accessible from ripple emulator

var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://www.bing.com", true);
xmlhttp.send();

But the request is not passed through the Ripple XHR Proxy.

Request:

GET / HTTP/1.1
Host: www.bing.com
Connection: keep-alive
Origin: http://localhost:4400
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36
Accept: */*
Referer: http://localhost:4400/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: da,en;q=0.8,en-US;q=0.6

Error:

XMLHttpRequest cannot load http://www.bing.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4400' is therefore not allowed access.

Cross domain proxy is set to: local

It seems to start the proxy:

INFO: Server instance running on: http://localhost:4400
INFO: CORS XHR proxy service on: http://localhost:4400/ripple/xhr_proxy
INFO: JSONP XHR proxy service on: http://localhost:4400/ripple/jsonp_xhr_proxy
Cordova 3.0 Project detected...
INFO: Could not find cordova as a local module. Expecting to find it installed globally.
INFO: Using Browser User Agent (String)
refreshing project (platform: android) ...
... done.

Any suggestions on what i am doing wrong here?

Community
  • 1
  • 1
KasperT
  • 125
  • 1
  • 1
  • 7

1 Answers1

0

In other posts people have suggested using a Chrome CORS extension, but since Chrome 48 all the CORS extensions seem to have stopped working.

I posted this workaround at Visual Studio, Ripple Emulator and CORS/Cross Domain Ajax, but I'll outline it again below:

  1. In your Chrome installation directory - probably C:\Program Files (x86)\Google\Chrome\Application - create a shortcut to the chrome.exe
  2. Right click on this shortcut and select Properties
  3. On the Shortcut tab, in the Target field append the following two fields --allow-file-access-from-files --disable-web-security 4 . Save this and rename the shortcut to "Google Chrome - Debug with Ripple"
  4. Right click on it and select Pin to Start Menu

This shortcut will allow you to run Chrome with no web security, which allows CORS in Ripple. By using a shortcut this will not interfere with your normal use of Chrome. Now in order to use Ripple

  1. In Visual Studio debug your app which will start Ripple in its own Chrome instance
  2. Now open the start menu and click on the pinned "Google Chrome - Debug with Ripple" shortcut
  3. A second instance of Chrome will launch with a warning of "You are using an unsupported command-line flag: -- disable-web-security. Stability and security will suffer."
  4. Copy the Ripple proxy URL from the Visual Studio instance to this new one, for example http://localhost:4400/index.html?enableripple=cordova-3.0.0-NexusS
  5. Your CORS requests will now work in Ripple.

Note that Visual Studio has just been used to launch Ripple. Debugging will need to take place using Chrome's Developer Tools.

Note also that you can double check that Chrome is using your shortcut flags by browsing to the url chrome://version/

Remember to test on a device as well, but once you've proved your app is working the above is easier for day to day debugging.

Community
  • 1
  • 1
Chris
  • 233
  • 2
  • 13