Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cross-origin redirect inside of an iframe is interpreted as a redirect for the app #78

Closed
glennfu opened this issue Jan 28, 2025 · 5 comments
Assignees

Comments

@glennfu
Copy link

glennfu commented Jan 28, 2025

I have a page loading with a standard inline YouTube embed:

<iframe
  width="480"
  height="270"
  src="https://www.youtube.com/embed/dQw4w9WgXcQ?playsinline=1&showinfo=0&rel=0&iv_load_policy=3&color=white"
  frameborder="0"
  allowfullscreen
></iframe>

Since updating from 1.1.0 to 1.1.1, I assume as a result of #70, when this page loads it instantly bounces over to the Safari app at this YouTube url.

I'm not sure what the best solution is, but my hope would be that in detecting things like Cross-origin redirects, it could safely ignore those that aren't happening on the parent frame.

To reproduce, you can take the Demo app and locally serve up just the iframe html above.

@noah44846
Copy link

I also encountered the same issue, but for the Google Maps embed. For me, it also worked in 1.1.0 but not in 1.1.1. Here is the iframe:

<iframe
    allowfullscreen=""
    class="mb-2 rounded-3"
    frameborder="0"
    height="150"
    width="100%"
    src="https://www.google.com/maps/embed/v1/place?key=<key...>&q=<query...>&zoom=15"
></iframe>

The thing is that for me when I navigate to the page the containing the iframe there is no issue, but when I pull-to-refresh the WebView it opens the embedded link in the browser.

@svara svara self-assigned this Jan 30, 2025
@darthdie
Copy link

We're encountering the same thing and have opened up a reproducible example here:
hotwired/hotwire-native-demo#13 

It seems to only happen during a ColdBootVisit for us.

Adding

        guard let targetFrame = navigationAction.targetFrame, targetFrame.isMainFrame else {
            decisionHandler(.cancel)
            return
        }

into ColdBootVisit func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void)

Fixes the issue.

@svara
Copy link
Contributor

svara commented Jan 31, 2025

Hey guys, we've merged #80 which should address this issue.
Could you give it a test on main? Thanks!

The thing is that for me when I navigate to the page the containing the iframe there is no issue, but when I pull-to-refresh the WebView it opens the embedded link in the browser.

@noah44846 Only a cold boot visit is affected by this. Since pull to refresh initiates a cold boot visit, you ran into this behaviour.

@noah44846
Copy link

Hey guys, we've merged #80 which should address this issue. Could you give it a test on main? Thanks!

The thing is that for me when I navigate to the page the containing the iframe there is no issue, but when I pull-to-refresh the WebView it opens the embedded link in the browser.

@noah44846 Only a cold boot visit is affected by this. Since pull to refresh initiates a cold boot visit, you ran into this behaviour.

I tested it on our project, and it fixes the issue we've had. Thanks!

@glennfu
Copy link
Author

glennfu commented Jan 31, 2025

Yes this solves my issue. Thank you!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

5 participants