Mapbox-gl-js: Add support for XHR requests to the file system

Created on 29 Sep 2016  路  1Comment  路  Source: mapbox/mapbox-gl-js

XHR requests to file:/// protocol may return xhr.status: 0 on success in various browsers (at least Chrome on Android and Firefox on Desktop).

In gl-js, the getJSON and getArrayBuffer methods call success when:

xhr.status >= 200 && xhr.status < 300 && xhr.response

to fully support the file:/// protocol, it should be something like:

((xhr.status >= 200 && xhr.status < 300) || (xhr.status === 0 && xhr.responseURL.split('://')[0] === 'file')) && xhr.response

mapbox-gl-js version:

Steps to Trigger Behavior

  1. Add sprites or fonts from the local filesystem on an Android device
  2. Attempt to load the files from a file:/// url
  3. The file will load successfully, and the response will be available in xhr.response, but the handlers will fire an error event due to xhr.status: 0

    Actual Behavior

XHR.status: 0 from the file:/// protocol is handled as an error

Expected Behavior

XHR.status: 0 from the file:/// protocol should be handled as a success

>All comments

We've previously declined to do this in #2466 and #1623 -- file:// XHR just has too many gotchas. Run a local server instead.

Was this page helpful?
0 / 5 - 0 ratings