Repository navigation
Add evaluateJavaScript to iOS WebView #8798
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
Changes from all commits
00992b3
4e0e9e8
9d38031
89e6d14
74971b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -461,6 +461,16 @@ var WebView = React.createClass({ | |
| ); | ||
| }, | ||
|
|
||
| /** | ||
| * Evaluate JavaScript on the current page. | ||
| */ | ||
| evaluateJavaScript: async function(script: string): Promise { | ||
| var escaped = JSON.stringify(script).replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029'); | ||
| var wrapped = 'JSON.stringify(eval(' + escaped + '))'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why enforce this
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
#1191 has the relevant history (starting with @spicyj's comment). For forward compatibility with The naive approach for doing this would be to simply say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with using eval in this way is that if the page enforces a Content Security policy that restricts the use of |
||
| var resultString = await RCTWebViewManager.evaluateJavaScript(this.getWebViewHandle(), wrapped); | ||
| return JSON.parse(resultString); | ||
| }, | ||
|
|
||
| /** | ||
| * We return an event with a bunch of fields including: | ||
| * url, title, loading, canGoBack, canGoForward | ||
|
|
||
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 think Flow will soon require type parameters (not sure what they are called), so may be we have to change it to
Promise<any>