Skip to content

Use of fetch API breaks cordova apps #7603

Closed

Description

@gpiffault

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

Activity

  1. mourner commented on Nov 21, 2018

    @mourner
    Member

    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

  2. kkaefer commented on Nov 23, 2018

    @kkaefer
    Member

    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.

  3. gpiffault commented on Nov 23, 2018

    @gpiffault
    Author

    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.

  4. mourner commented on Nov 23, 2018

    @mourner
    Member

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

  5. ansarikhurshid786 commented on Dec 4, 2018

    @ansarikhurshid786

    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.

  6. kkaefer commented on Jan 30, 2019

    @kkaefer
    Member

    @gpiffault This should be fixed in #7818.

  7. gpiffault commented on Jan 31, 2019

    @gpiffault
    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.

  8. denis1994 commented on Jun 13, 2019

    @denis1994

    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.

  9. added a commit that references this issue on Jun 19, 2019
  10. denis1994 commented on Jul 8, 2019

    @denis1994

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions