Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aldistel opened this issue Jun 14, 2019 · 12 comments
Closed

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

aldistel opened this issue Jun 14, 2019 · 12 comments
Labels
Bug Component: WebView Related to the WebView component. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@aldistel
Copy link

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 61ca119#diff-17ddfccc3e39071c0aa51f82677e6d68 :

image

Correct method to use instead of stringByReplacingPercentEscapesUsingEncoding is stringByRemovingPercentEncoding.

cc @pvinis

@aldistel aldistel added the Bug label Jun 14, 2019
@react-native-bot react-native-bot added Component: WebView Related to the WebView component. Platform: iOS iOS applications. labels Jun 14, 2019
@guhungry
Copy link
Contributor

React Native's WebView was deprecated please migrate to Community version

@Ruanyang2015
Copy link

me too

@Atanatous
Copy link

I had the same error with Expo SDK 33 and iOS.
So I have tried to use react-native-webview from community, and it works to me!
In this change, if you use postMessage function, you should change windows.postMessage() to window.ReactNativeWebView.postMessage().

However, it shows error message as belows when I inject this code
Error evaluating injectedJavaScript: This is possibly due to an unsupported return type. Try adding true to the end of your injectedJavaScript string..

If you try this and solve, please notice me, too!

@yurnery
Copy link

yurnery commented Jul 8, 2019

me too

@Ruanyang2015
Copy link

me too

改 OC原生可以避免它

@aijason
Copy link

aijason commented Jul 11, 2019

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

@Ruanyang2015
Copy link

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

I tried your method, but it still went wrong.

@hyper750
Copy link

hyper750 commented Aug 1, 2019

I solve it with

let string_data = m.nativeEvent.data;
if(Platform.OS === "ios"){
	// IOS returns the data url encoded/percent-encoding twice
	// unescape('%257B') -> %7B
	// unescape(%7B) -> {
	string_data = unescape(unescape(string_data));
}

@t-benze
Copy link

t-benze commented Aug 14, 2019

somehow adding useWebKit={true} fix the issue.


seems the issue only affect UIWebView, not WKWebView

@bauerlaci
Copy link

bauerlaci commented Aug 14, 2019

somehow adding useWebKit={true} fix the issue

it's working for me, thanks a lot!
(using expo sdk 33 on iOS)

salujaharkirat added a commit to wealthy/react-native-highcharts that referenced this issue Sep 26, 2019
@stale
Copy link

stale bot commented Nov 13, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Nov 13, 2019
@stale
Copy link

stale bot commented Nov 20, 2019

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Nov 20, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Nov 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Component: WebView Related to the WebView component. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

10 participants