Skip to content

feat(ios): Added support for https urls access to local files. #296

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

guylando
Copy link

@guylando guylando commented Mar 3, 2019

Currently if you load a remote https page (on domain xxx.com) on the ios webview then cdvfile://... urls requested from that page for active content such as js and css files are blocked by the mixed content policy.
This PR solves this by allowing access to cdvfile://localhost/bundle/www/cordova.js using the url: https://xxx.com/cdvfile/bundle/www/cordova.js
Since this url is https and from same domain as the remote https page, this works!

Reference:
https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content#Mixed_passivedisplay_content
https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content/How_to_fix_website_with_mixed_content

Fixed typo
@syonip
Copy link

syonip commented May 28, 2019

@guylando I'm having this issue too.
Any progress on this PR?
Do you need help doing the android side? Happy to help

@guylando
Copy link
Author

@syonip my changes work well, seems just that this repository is not maintained too much.
android does not require those changes since there is a flag in android webview which disables mixcontent being blocked.

@guylando
Copy link
Author

@janpio I think the android tag is wrong since this is an ios modification

@janpio janpio changed the title Added support for https urls access to local files. feat(ios): Added support for https urls access to local files. Jul 4, 2019
@janpio
Copy link
Member

janpio commented Jul 4, 2019

Correct, that was a miscategorization. Fixed it.

@janpio janpio closed this Jul 4, 2019
@janpio
Copy link
Member

janpio commented Jul 4, 2019

Restart tests.

@janpio janpio reopened this Jul 4, 2019
@janpio
Copy link
Member

janpio commented Jul 4, 2019

Hey @guylando, does xxx.com have any meaning in that URL? The related Android PR uses just https://cdvfile/ which seems like a cleaner design, do you agree?

@janpio janpio closed this Jul 4, 2019
@janpio
Copy link
Member

janpio commented Jul 4, 2019

CI: Please run the tests again.

@janpio janpio reopened this Jul 4, 2019
@janpio janpio closed this Jul 4, 2019
@janpio
Copy link
Member

janpio commented Jul 4, 2019

CI: Once more please.

@guylando
Copy link
Author

guylando commented Jul 4, 2019

@janpio cleaner than what? the android side I use is your original implementation so are you asking if his PR is cleaner than your original implementation? all I did in android is allow your original implementation to work in a mixed content environment

@janpio
Copy link
Member

janpio commented Jul 5, 2019

My comment contains a link to the PR I referred to - @syonip created a similar PR for Android which uses a slightly different "design" for the special URL.

@janpio
Copy link
Member

janpio commented Jul 5, 2019

The more important question to be able to understand and test your PR was this:

Hey @guylando, does xxx.com have any meaning in that URL?

Can xxx.com be anything? Or does it have to be the actual website that is loaded via https:// in the webview for this to work?

If this is true, am I correct that one could also describe this PR as to adding a special cdvfile folder https websites that is intercepted locally and redirected to the file plugin to be able to server local files?

@gwynjudd
Copy link

Does this feature work for WKWebView? Please note that WKWebView does not yet support NSURLProtocol (https://stackoverflow.com/questions/24208229/wkwebview-and-nsurlprotocol-not-working). Also, even though there is WKURLSchemeHandler, you cannot register a scheme handler for https.

I have tried this patch in iOS device with WKWebView, and it doesn't appear to work for me. Has it worked for you at all?

@TaDaa
Copy link

TaDaa commented Aug 8, 2019

Same issue -- haven't been able to get this work on WKWebView. From a dev standpoint on IOS this is frustrating (and also due to how inconsistent the implementations are between platforms). Just about every major release the internal mechanism for serving files has changed without what feels like much consideration.

@gwynjudd
Copy link

gwynjudd commented Aug 8, 2019

I've gotten access to local files working in WKWebView using a WKURLSchemeHandler but the url schema has to be non http/https (e.g. cdvfile: works).

@TaDaa
Copy link

TaDaa commented Aug 9, 2019

Are you accessing cdvfile: from a "https" site? http should work fine, but https seems to throw [blocked] due to mixed-content (https to non-secure).

@gwynjudd
Copy link

I've been using https

@lovelyelfpop
Copy link

Has this pr been merged?

@guylando
Copy link
Author

@janpio using https://cdvfile will create CORS errors probably. better to use https://xxx.com/cdvfile where xxx.com is the site the browser is viewing and this way there are no CORS problems

@weareu
Copy link

weareu commented Feb 7, 2022

This is now also broken on Android Template 10 for cordova as that requires serving via https: cvdfile no longer works. Using a virtual folder is best due to CORS. Changing the hostname is not a good idea. Once this is merged the same thing should happen for Android to standardise.

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

Successfully merging this pull request may close these issues.

7 participants