Skip to content

Support custom scheme or domain for local content on Android #1004

@AshleyScirra

Description

@AshleyScirra

Feature Request

As of cordova-ios 6.0.0, you can use the following in config.xml:

<preference name="scheme" value="app"/>
<preference name="hostname" value="localhost"/>

Then the app runs on app://localhost instead of file://. This does not appear to work on Android though - having tried it the app still runs at a file:// URL.

Motivation Behind Feature

Running on file: brings a number of origin-related problems. Notably on file:, the browser treats every resource as a different origin, causing some features to be blocked. In particular, fetch() cannot be used at all, because it's actually written in to the specification that it can just throw on file: protocol and that's what Chromium chooses to do.

Further, this will allow Cordova Android apps to more closely align their codebases with iOS, since in both cases it can be running on the same URL (app://localhost) with identical capabilities regarding the security origin, use of fetch(), etc.

Alternatives or Workarounds

Right now we are forced to use cordova-plugin-file to read local files, and in many cases use some ugly code involving blobs and blob URLs to work around restrictions with file: URLs. We also have to maintain two significantly different codepaths, one using fetch(), the other using cordova-plugin-file methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions