Skip to content
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

Use of fetch API breaks cordova apps #7603

Closed
gpiffault opened this issue Nov 20, 2018 · 9 comments
Closed

Use of fetch API breaks cordova apps #7603

gpiffault opened this issue Nov 20, 2018 · 9 comments
Labels

Comments

@gpiffault
Copy link

mapbox-gl-js version: 0.51.0

browser: Chrome 70 (webview)

#7371 introduces a bug in cordova apps loading local assets. The fetch API doesn't support the file: scheme whereas xhr does (JakeChampion/fetch#92 (comment)) so when style specification or images are stored locally, they won't load after 0.51.0 (works fine up to 0.50.0).

For reference, I commented on the commit here eec8cd5#commitcomment-31351193

@mourner
Copy link
Member

mourner commented Nov 21, 2018

Yeah, we should probably switch to XHR when requesting a URL with a file protocol. Would you like to do a PR with the fix? cc @kkaefer

@kkaefer
Copy link
Member

kkaefer commented Nov 23, 2018

It looks like no browser allows access via file:// URLs anyway´ due to security constraints. E.g. Chrome reports:

Access to XMLHttpRequest at 'file://test/integration/tiles/14-8803-5375.mvt' from origin 'file://' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

@gpiffault
Copy link
Author

gpiffault commented Nov 23, 2018

This behaviour is disabled in the webview cordova uses (only for xhr, not for fetch, it's probably not possible for fetch). Unfortunately I think it's not trivial to test it out, you need to install cordova, make a sample project and run it on a device. I can help with the testing.

@mourner
Copy link
Member

mourner commented Nov 23, 2018

@kkaefer it's possible in certain environments like Cordova. We had related PRs before, e.g. this one #6610

@ansarikhurshid786
Copy link

I am also using ionic 3 which use cordova for building ios and android application. In my application it is working fine. I seen my application running on local web server.

@kkaefer
Copy link
Member

kkaefer commented Jan 30, 2019

@gpiffault This should be fixed in #7818.

@kkaefer kkaefer closed this as completed Jan 30, 2019
@gpiffault
Copy link
Author

@kkaefer Thanks. Actually it didn't directly fixed my use case besause I used relative URLs to load the local assets so the regexp isn't enough in this case. It works when I convert my URLs to absolute but it's not quite straightforward, you might get new bug reports about this.

@denis1994
Copy link

I have the same problem. I use mapbox in react project with cordova but my pins images aren't loaded. Downgrading to 0.50.0 works fine. I also use relative paths.

gpiffault pushed a commit to gpiffault/mapbox-gl-js that referenced this issue Jun 19, 2019
@denis1994
Copy link

@gpiffault I will test your commit and report here. Perhaps they can take it to the actual version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants