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.

RN 0.59.8: postMessage result from iOS WebView is double-encoded

See original GitHub issue

The data returned to onMessage WebView callback on iOS is double-percent-encoded.

React Native version: 0.59.8

Steps To Reproduce

  1. Inject a JS into WebView that calls e.g. window.postMessage('https://test.com')
  2. 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 :

image

Correct method to use instead of stringByReplacingPercentEscapesUsingEncoding is stringByRemovingPercentEncoding.

cc @pvinis

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
t-benzecommented, Aug 15, 2019

somehow adding useWebKit={true} fix the issue.


seems the issue only affect UIWebView, not WKWebView

3reactions
aijasoncommented, Jul 11, 2019

Platform.OS === 'ios' ? decodeURIComponent(decodeURIComponent(event.nativeEvent.data)) : event.nativeEvent.data

Read more comments on GitHub >

github_iconTop 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 >

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