-
Notifications
You must be signed in to change notification settings - Fork 49
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
Access to fetch at external_redirect_url
from origin our_url
has been blocked due to CORS policy
#320
Comments
You have to intercept navigations to external links and create a separate WebView to show them. WebView from Turbo is only intended to be used with turbo.js itself. |
Thanks @MichalSznajder ! I already have some code doing that here: interface NavDestination : TurboNavDestination {
override fun shouldNavigateTo(newLocation: String): Boolean {
Log.d("Navigation", "Navigation to ${newLocation} from ${location}")
return when (isNavigable(newLocation)) {
true -> true
else -> {
launchCustomTab(newLocation)
false
}
}
}
private fun isNavigable(location: String): Boolean {
return location.startsWith(BuildConfig.BASE_APP_URL)
}
} But the logging (Navigation to ${newLocation} from ${location}") only shows up on the first link. So it shows up for my internal link, returns true, and continues within the WebView with turbo.js. However, it does not log the above after the redirect. So, that mechanism fails here. It's very possible I'm intercepting the requests at the wrong point in code, but if not, this is more internal to the I think we're getting closer. I'll keep looking through the docs to better understand if I'm intercepting the request properly. |
I think I've verified that this is a bug in hjhart/turbo-native-demo@767139c You can see how the external links work just fine, but a redirect to an external link does now. See the video below, running against a local server and using the default turbo-android demo code. Screen.Recording.2024-03-27.at.12.01.32.PM.movThis is what shows up in LogCat at the time:
|
@jayohms I'm happy to take this work on, as it is blocking my companies critical path, but do you have any pointers as to what code I might want to touch before I dive into this work? |
@hjhart I dug into this and it's is an issue in both Due to the CORS policy in |
@jayohms, wow, that works perfectly. Thanks so much! Screen.Recording.2024-03-28.at.9.14.22.AM.mov |
The fix is now available in 7.1.2: https://github.com/hotwired/turbo-android/releases/tag/7.1.2 |
Hey @jayohms, thanks for the quick release! Does this also require an upgrade of turbo.js, or turbo-rails? |
Edit: Opened up another issue #327 |
Expected behavior:
When tapping on a link that redirects to an external site
The external site should load correctly
Actual behavior:
"Error loading page" screen
Along with this in the Logcat output:
Isolating the problem further, if instead I have the original link pointing to
https://our-app.formstack.com/forms/redacted
instead ofhttp://app.android-local.dev-hellobrightline.com:3000/formstack/forms/3f76559e-bb49-4465-a7ab-ab4e75b80f29
, it works just fine. The introduction of the redirect seems to break it.I noticed the CORS error in firefox and chrome, and disabling turbo fixed the request since it stopped being a
fetch
via turbo.js. Now it's happily a link that redirects successfully. But in our turbo-android app, it is still failing.Since I don't have control over the formstack servers, I cannot modify the CORS headers successfully.
I'm going to continue to dive into this issue, but wanted to post it here for posterity, and to hopefully get some help from anyone who has encountered this issue previously.
Thanks in advance.
The text was updated successfully, but these errors were encountered: