turbolinks / turbolinks-ios

Native iOS adapter for building hybrid apps with Turbolinks 5
MIT License
880 stars 92 forks source link

JavaScript error: Cross origine request for webcal:// #166

Closed tony42 closed 4 years ago

tony42 commented 4 years ago

We are trying to load a webcal:// URL from the same domain we run the whole app from. It appears that Turbolinks are trying to load this URL as a "local" page but iOS treats it as an external site.

I see this error in XCode console:

2020-01-31 12:28:58.902232+0100 HlidackyMobileApp[7011:2628385] Error evaluating JavaScript function 'webView.changeHistoryForVisitWithIdentifier': SecurityError: Blocked attempt to use history.pushState() to change session history URL from https://www.hlidacky.cz/rezervace to webcal://www.hlidacky.cz/export_calendars/XiT5RF3ZPMyPFbXiwJpAK79N.ics. Protocols, domains, ports, usernames, and passwords must match.

And Turbolinks will call session(_ session: Session, didFailRequestForVisitable visitable: Visitable, withError error: NSError)

If I try to load a webcal:// URL form a different domain, everything works as expected.

My best guess is that Turbolinks JavaScript compares the domain part of the URL and if it matches, it loads the URL as "internal" which causes the error. If that is correct, one needs to extend to code to compare the domain and the URL scheme.

petrsigut commented 4 years ago

In the Basecamp iOS app, it works flawlessly, but I do not know if there are some more js to handle the calendar opening. Any point in the right direction appreciated!

IMG_0264

zachwaugh commented 4 years ago

For links like that, Turbolinks will ignore them, and they will hit the WKNavigationDelegate. In Basecamp, we process any URLs there and send them through our router which determines where they need to open. For something like that, we just open them with the system.

I'm not sure where that error is coming from since I can't reproduce in Basecamp. Possibly, you're trying to send that link back through Turbolinks?

tony42 commented 4 years ago

@zachwaugh WKNavigationDelegate was the hint I needed :-) Turbolinks.Session is actually the delegate and it correctly calls SessionDelegate.session(self, openExternalURL: URL)

The issue was on our side in the external URL handling.

Closing this issue but thanks for the assistance.