-
Notifications
You must be signed in to change notification settings - Fork 32
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
Fix red screen due to window.postMessage override #22
base: master
Are you sure you want to change the base?
Fix red screen due to window.postMessage override #22
Conversation
src/react-native/hoc.js
Outdated
return ( | ||
<WebView | ||
{...this.props} | ||
injectedJavaScript={patchPostMessageJsCode} | ||
javaScriptEnabled={true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is enabled by default. Am I wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you're right, let me remove it.
Ok now it should be good, sorry for the wrong code formatting on the first commit, I didn't realize that prettier would change that before pushing. It should be fixed on the last one. |
No worries, it's good 👍 |
Well apparently setting the The piece of code in this PR enables to override |
Any update on this pull request? I've integrated @nacho-carnicero's fix into my project manually to resolve the |
hey @ptvandi, thanks for your feedback. I will take a closer look this evening |
@nacho-carnicero question for you: why is this patch should be evaluated inside |
FWIW, I pulled this patch out of the render method and defined the function above the HOC declaration. No need to create the function each time the component is rendered. |
Yes you’re right the definitions of the variables can be pulled out of the render method. I’ll push a commit tomorrow morning with the changes. |
@R1ZZU @ptvandi I just pushed the changes, is it good for merging? |
@nacho-carnicero Not sure |
@R1ZZU What do you think of modifying import React from 'react';
import { WebView as NativeWebView } from 'react-native';
import { withMessaging } from './hoc';
const patchPostMessageFunction = () => {
var originalPostMessage = window.postMessage;
var patchedPostMessage = function(message, targetOrigin, transfer) {
originalPostMessage(message, targetOrigin, transfer);
};
patchedPostMessage.toString = () => {
return String(Object.hasOwnProperty).replace(
'hasOwnProperty',
'postMessage'
);
};
window.postMessage = patchedPostMessage;
};
const patchPostMessageJsCode =
'(' + String(patchPostMessageFunction) + ')();';
const WebViewWithPatchedPostMessage = ()=>{
return(
<NativeWebView
injectedJavaScript={patchPostMessageJsCode}
/>
);
};
export const WebView = withMessaging(WebViewWithPatchedPostMessage); That way |
@nacho-carnicero this looks better, however I wonder if there is a possibility to move this part of code to webview side? Smth like |
@nacho-carnicero did you have a chance to chech if this code injected in webview code fixes the issue? |
Sorry @R1ZZU I've been quite busy these last weeks, I didn't have a chance to look at this. Anyway since the problem comes from the react-native Webview component I doubt this would work putting it in the code corresponding to the web side. Maybe I have understood wrong what you are suggesting, could you provide some pseudo-code of what you have in mind? |
@nacho-carnicero I had no chance to dig to root cause of the issue this PR going to fix, so I'm just assuming if it also could be fixed from webview side javascript. Will this issue be fixed if this piece of code will be the first thing evaluated in webview code not with help of |
As far as I understand you would have to modify the React Native Webview component in order to avoid to use the |
@nacho-carnicero did you have a chance to actually reproduce this issue? I'm trying to get this error and see if this code actually fixes the issue, but I just can't get original |
Yes I've had it, you have to be in development mode though to encounter it (for example using the iOs simulator and clicking on the play button on XCode). |
@nacho-carnicero Thanks for the patch in this, I was able to just apply this patch to the normal |
This fixes #16 according to the fix given here facebook/react-native#10865 (comment)
Important : in order to try this remember to launch the packager resetting its cache in order to be sure that the updated package gets in the bundle, so run it with:
npm start -- --reset-cache