question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebView redirects into iFrame on Android

See original GitHub issue

Bug description:

WebView Component redirects into iFrame(s) when serving from static resources on Android. Used props are:

{
  source: {uri: 'file://<path/to/index.html>'}
  originWhitelist: ['*'],
  allowFileAccess: true
}

However it was working correctly on v.2.10.0. And here is a fork of working version that we’re stuck to use in our original app in order to get the right behavior.

To Reproduce: Here is the repo of an example app to reproduce error. You can download and examine the source code that i’m using in the example app

Expected behavior: WebView shouldn’t redirect into Iframe src on Android. The view in the iOS Simulator is expected.

Screenshots/Videos: Screenshots produced at latest version of react-native-webView (5.8.1) Android: (incorrect) and_5 8 1 iOS: (correct) iPhone_5 8 1

Environment:

  • OS: macOS Mojave
  • OS version: 10.14.4
  • react-native version: 0.59.5
  • react-native-webview version: > 2.10.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:11

github_iconTop GitHub Comments

1reaction
github-actions[bot]commented, Nov 16, 2019

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

1reaction
pluspolcommented, Aug 16, 2019

We might have found a fix for this. 😃 It seems that the iOS version contains a check preventing unwanted redirects of the main frame. The Android version doesn’t check this.

The following change to RNCWebViewManager.java adding the main frame check seems to fix the issue:

    @TargetApi(Build.VERSION_CODES.N)
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
      if (!request.isForMainFrame()) {
        return false;
      }

      final String url = request.getUrl().toString();
      return this.shouldOverrideUrlLoading(view, url);
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

WebView redirects into iFrame on Android · Issue #560 - GitHub
WebView Component redirects into iFrame(s) when serving from static resources on Android. ... However it was working correctly on v.2.10.0. And ...
Read more >
Android WebView, how to handle redirects in app instead of ...
So right now in my app the URL I'm accessing has a redirect, and when this happens the WebView will open a new...
Read more >
Intercept all requests in WebView on Android | by Andy Wang
I have a requirement that all HTTP requests from a WebView on Android need to be handled locally. For example, providing assets for...
Read more >
WebView - Android's most convenient footgun - byte.how
Exploring iframe security through an Android WebView lens. ... On click, a link redirects the top frame to a malicious page.
Read more >
Managing WebView objects - Android Developers
Android provides several APIs to help you manage the WebView objects that display web content in your app. This page describes how to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found