Fixing React Native WebView’s postMessage for iOS

Charles Stover
6 min readSep 23, 2018
The error that should have never been.

In 2016, GitHub user Robert Roskam (raiderrobert) opened an issue on the React Native repository reporting the error “Setting onMessage on a WebView overrides existing values of window.postMessage, but a previous value was defined”. In the two years since then, nothing has been done to resolve it within the internal React Native implementation of WebView.

The React Native community has forked WebView specifically to maintain it as a third party package and fix many of these ongoing issues. However, in order to implement these third party packages, you must be able to link React Native packages — react-native link react-native-webview. If you are able and willing to do this, your problem is solved. The installation instructions for the community edition of WebView are as simple as:

yarn add https://github.com/react-native-community/react-native-webview
react-native link react-native-webview

Note: In order to react-native link ..., you must first yarn global add react-native.

Unfortunately, if you are unable or unwilling to do this, there has simply been no solution to this problem. For years!

Users of Expo, for example, would have to eject their project and write their own native, non-JavaScript implementation of features. Expo will, theoretically, be using…

--

--

Charles Stover
Charles Stover

Written by Charles Stover

Staff+ front end engineer | Tech lead | Architect | quisi.do

Responses (4)