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.

Certain websites result in invariant violation in custom webview

See original GitHub issue

Bug description: Attempting to load certain websites from a custom webview results in an invariant violation:

Invariant Violation: requireNativeComponent: "RNCWebView" was not found in the UIManager.

This error is located at:
    in RNCWebView (at WebView.android.js:205)
    in RCTView (at View.js:45)
    in View (at WebView.android.js:208)
    in WebView (at App.js:18)
    in App (at renderApplication.js:35)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:98)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:115)
    in AppContainer (at renderApplication.js:34)

To Reproduce: CustomWebView.android.js:

const RCTCustomWebView = requireNativeComponent(
    "CustomWebView",
    CustomWebView,
    WebView.extraNativeConfig,
);

export default class CustomWebView extends Component {
    static propTypes = WebView.propTypes;

    render() {
        return (
            <WebView {...this.props} nativeConfig={{component: RCTCustomWebView}} />
        )
    }
}

CustomViewManager.java:

@ReactModule(name = CustomWebViewManager.REACT_NAME)
public final class CustomWebViewManager extends RNCWebViewManager {
    static final String REACT_NAME = "CustomWebView";

    protected static final class CustomWebView extends RNCWebView {
        CustomWebView(ThemedReactContext reactContext) {
            super(reactContext);
        }
    }

    public static class CustomWebViewClient extends RNCWebViewClient { }

    private ReactApplicationContext mContext;

    CustomWebViewManager(ReactApplicationContext reactApplicationContext) {
        super();
        mContext = reactApplicationContext;
    }

    @Override
    protected RNCWebView createRNCWebViewInstance(ThemedReactContext reactContext) {
        return new CustomWebView(reactContext);
    }

    @NonNull
    @Override
    public String getName() {
        return REACT_NAME;
    }

    @Override
    protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
        view.setWebViewClient(new CustomWebViewClient());
    }
}

CustomWebViewModule.java:

@ReactModule(name = CustomWebViewModule.REACT_NAME)
public class CustomWebViewModule extends RNCWebViewModule {
    static final String REACT_NAME = "CustomWebView";

    private final ReactApplicationContext mContext;
    private Handler mHandler;

    CustomWebViewModule(ReactApplicationContext reactContext) {
        super(reactContext);
        mContext = reactContext;
    }
}

App.js:

export default class App extends Component {
    render() {
        return (
            <CustomWebView source={{uri: "https://www.facebook.com"}} />
        );
    }
}

Compile and run on Android. See above error. Also works if loading https://www.gmail.com

However, this does work with other websites, for example if uri is “https://www.google.com”. Also works if using <WebView source={{uri: "https://www.facebook.com"}} /> instead of CustomWebView

Expected behavior: Facebook and Gmail should load as expected.

Environment:

  • OS: MacOS Mojave
  • OS version: 10.14.15
  • react-native version: cli: 2.0.1, library: 0.59.8
  • react-native-webview version: 6.2.2
  • Phone: Pixel 2 XL
  • Android Build: PQ3A.190605

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10

github_iconTop GitHub Comments

1reaction
magbicalemancommented, Sep 16, 2019

image

Curious if anyone got this resolved. I tried running react-native link react-native-webview but no success.

The following worked for me: https://github.com/react-native-community/react-native-webview/issues/161#issuecomment-441971014

running pod install in the ios folder.

0reactions
github-actions[bot]commented, Nov 27, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Certain websites result in invariant violation in custom webview
I get the very same error using the simplest of code. Without webview it works fine. import React, {Component} from 'react'; import { ......
Read more >
What is the right way to use WebView in React Native
Trying to use WebView from 'react-native-webview' to render URL ... saying: Invariant Violation: requireNativeComponent: "RNCWebView" was ...
Read more >
WebView - Android Developers
WebView objects allow you to display web content as part of your activity layout, but lack some of the features of fully-developed browsers....
Read more >
Custom WebView - React Native
While the built-in web view has a lot of features, it is not possible to handle every use-case in React Native. You can,...
Read more >
HTML Standard
... 3 Semantics, structure, and APIs of HTML documents; 4 The elements of HTML; 5 Microdata; 6 User interaction; 7 Loading web pages;...
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