RN 0.59.8: postMessage result from iOS WebView is double-encoded
See original GitHub issueThe data returned to onMessage WebView callback on iOS is double-percent-encoded.
React Native version: 0.59.8
Steps To Reproduce
- Inject a JS into WebView that calls e.g.
window.postMessage('https://test.com')
- The onMessage handler will receive double-encoded value:
<WebView onMessage={onMessage} ... />
function onMessage(event) {
console.log(event.nativeEvent.data); // "https%253A%252F%252Ftest.com"
}
This was introduced in https://github.com/facebook/react-native/commit/61ca11965046f75e7500e5152c5f2b60df2a2cd5#diff-17ddfccc3e39071c0aa51f82677e6d68 :
Correct method to use instead of stringByReplacingPercentEscapesUsingEncoding
is stringByRemovingPercentEncoding
.
cc @pvinis
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:12 (1 by maintainers)
Top Results From Across the Web
React Native WebView postMessage does not work
Does anyone know why the web app is not receiving the messages? Tested with both Android and iOS. Related documentation: https://facebook.github ...
Read more >Fixing React Native WebView's postMessage for iOS
The rn-webview package works by directing window.postMessage traffic to history.pushState instead. While React Native's iOS implementation cannot handle ...
Read more >WebView - React Native
postMessage accepts one argument, data , which will be available on the event object, event.nativeEvent.data . data must be a string. Type, Required....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
somehow adding
useWebKit={true}
fix the issue.seems the issue only affect UIWebView, not WKWebView
Platform.OS === 'ios' ? decodeURIComponent(decodeURIComponent(event.nativeEvent.data)) : event.nativeEvent.data