0

Trying to use Ratchet's push.js, but doesn't work. What I have in console:

[Error] Error: Could not get: file:///var/mobile/Applications/337585D8-89E1-4810-AB37-0A6DD2DA3A34/Gustav.app/www/booking.html
failure (ratchet.js, line 446)
onreadystatechange (ratchet.js, line 371)

If you will tap link like ten times you start to receive this:

[Error] TypeError: 'undefined' is not an object (evaluating 'cacheMapping[PUSH.id].url')
cachePush (ratchet.js, line 202)
PUSH (ratchet.js, line 392)
touchend (ratchet.js, line 258)

All this console data from real device tests (iOS 7.1), wrapper is Cordova CLI 3.4.1-0.1.0.

File booking.html exist, native safari failure like this

[Error] Failed to load resource: The requested URL was not found on this server. (menu.html, line 0)

doesn't appear.

Mo.
  • 26,306
  • 36
  • 159
  • 225

1 Answers1

2

push.js does not support file:// protocol.

Ratchet uses XHR requests to fetch additional pages inside the application. Due to security concerns, modern browsers prevent XHR requests when opening files locally (aka using the file:// protocol); consequently, Ratchet does not work when opened directly as a file. A common solution to this is to simply serve the files from a local server. One convenient way to achieve this is to run python -m SimpleHTTPServer to serve up the files in the current directory to http://localhost:<port>

Also see this issue and this issue submitted on Github

It seems like this is a common issue with using Cordova and Ratchet.

Schmalzy
  • 17,044
  • 7
  • 46
  • 47
  • 1
    Thanks! Here is link(https://github.com/artemave/ratchet/commit/5ccfdd765ecd15666b83b0b9abc15e4c120b7713) to commit that adding file:// support in ratchet, by the way. – lenyapugachev Apr 27 '14 at 04:46
  • @lenyapugachev hm doesn't really make any sense to use ratchet with Cordova then if file p. can't be used. Do you know when file:// will be supported? – Kallewallex Jul 20 '14 at 19:13
  • The ajax request succeeds but returns a status code of 0 for iOS 7.1. Allowing failed status `xhr.status === 0 (line 383 : ratchet.js)` allows page transitions when installed on a device. – kindasimple Oct 10 '14 at 20:28