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

fix: Normalize URLs on Ionic WKWebViews #228

Closed
wants to merge 1 commit into from

Conversation

Maistho
Copy link
Contributor

@Maistho Maistho commented Apr 26, 2018

Normalizes URLs on ionics wkwebview.

Recommended by the Ionic devs as a reasonable solution.
ionic-team/cordova-plugin-ionic-webview#76 (comment)

fixes #223

Let me know if there's anything else I've missed!

lib/imgcache.js Outdated
return (typeof entry.toURL === 'function' ? Helpers.EntryToURL(entry) : entry.toURI());
var url = (typeof entry.toURL === 'function' ? Helpers.EntryToURL(entry) : entry.toURI());
// Ionic has a URL normalization method for WKWebView (#223)
var normalizedUrl = window.Ionic && window.Ionic.normalizeURL && window.Ionic.normalizeURL(url) || url;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use WKWebView without having Ionic in your stack. Thus, the solution should not rely on its existence. And if your problem is Ionic specific, it shouldn't be solved here.

Copy link
Contributor Author

@Maistho Maistho Sep 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it will only use Ionic if it exists, in order to be compatible with Ionic. Without this piece of code, images don't load at all in Ionics webview unless everyone adds similar code themselves.

So any non-Ionic users will not see any difference, and any Ionic users will have it work out of the box. Seems helpful to me. 🤷‍♀️

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the result could be even more confusing to users because the behavior will be completely different depending on what dependencies are used in the project and part of the behavior of the plugin will be defined elsewhere.

You also just noticed yourself that this integration is apparently bound to break when the Ionic team makes changes to their API. Maintainers of this code should not have to care about Ionic IMHO.

If you're in Angular land, it should be trivial to sanitize your URLs before passing them to imgcache.js, we do so as well in our code. If that is not possible or undesirable, why not pull in the same sanitation code Ionic uses and replicate it in the Helper section of the plugin? Then it would work for everyone.

Anyway, I'm not the maintainer of this project. Just wanted to share my thoughts and possibly reach a better solution :)

@Maistho
Copy link
Contributor Author

Maistho commented Sep 12, 2018

I rebased it and updated to support v2 of ionics webviews. They changed the naming of the function around, and it is now required for android as well.

https://github.com/ionic-team/cordova-plugin-ionic-webview#migrating-to-2x

@Maistho
Copy link
Contributor Author

Maistho commented Sep 28, 2018

Hey, that's odd! What version of cordova-file-plugin are you using?
I'll patch it to support cdvfile:// URLs anyway I think.

Since v1.1.0 toURL shouldn't return cdvfile:// urls anymore.
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#upgrading-notes

In v1.1.0 the return value of toURL() was changed (see CB-6394) to return an absolute 'file://' URL. wherever possible. To ensure a 'cdvfile:'-URL you can use toInternalURL() now.

Edit: Even more odd is that I cannot see the comment from @phillipplum 🤷‍♂️

@phillipplum
Copy link

phillipplum commented Sep 28, 2018

I use the plugin-version 6.0.1. Edit: Strange @Maistho :/

@Maistho
Copy link
Contributor Author

Maistho commented Aug 27, 2020

I'm closing this PR since it probably shouldn't be merged. If this is still an issue I think adding some documenation in the README.md would be preferable.

@Maistho Maistho closed this Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unsupported URL issue on WKWebView
3 participants