-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ajax when loading local files on iOS web view #6610
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oscarfonts looks like this PR has gone askew. Can you rebase on master and make sure the PR only contains the commit you added?
I'm also not sure this should be fixed on the GL JS side since it follows the specs, and requesting file:// files with Ajax is usually prohibited due to security restrictions. Could there be a workaround on the Cordova/app side instead?
9ea7464
to
4031b50
Compare
Cleared PR with rebase. Thanks! Didn't find a simpler way to pass a local (offline) resource to mapbox-gl. Alternatives were: either forking the library to replace ajax calls with some other (non-http, probably environment specific) mechanism to access local resources, or embedding a local http server into the App. I can keep my fork if you feel this too hacky, I just thought it could go upstream for a more offline-friendly library, so to speak. |
@oscarfonts is the way Cordova behaves with Ajax + local files (e.g. the 0 status code) documented somewhere? |
The description of this behavior can be found on different forums (pouchdb, jquery, phonegap): pouchdb-community/pouchdb-load#11 See how jQuery deals with it: In fact, different browsers behave differently. For instance, in Android you'll get a 200 OK code. In general, the HTTP response status code is meaningless if there was no HTTP transaction at all. So, this PR will ignore status code when the |
@oscarfonts sorry for a delay — maybe let's just accept
The docs suggest that |
@mourner ok, done |
When running in iOS webview (cordova app), we detected that loading local resources (
file:///...
urls) is returning a "0" status code (instead of "200 OK").Included this case in util.ajax, so local files are fetched without checking the response status code value.
Tried to add a unit test, but sinon's FakeXMLHttpRequest doesn't provide the standard responseURL property we are reading. At least made sure actual unit tests are passing. :)