-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
injected javascript comments now work on android #12321
injected javascript comments now work on android #12321
Conversation
Does this means it will only work properly with comments on kitkat+? |
@mishuagopian I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project. |
@@ -273,7 +273,12 @@ public void callInjectedJavaScript() { | |||
if (getSettings().getJavaScriptEnabled() && | |||
injectedJS != null && | |||
!TextUtils.isEmpty(injectedJS)) { | |||
loadUrl("javascript:(function() {\n" + injectedJS + ";\n})();"); | |||
String code = "(function() {\n" + injectedJS + ";\n})();"; |
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.
Why do we need this wrapping here?
Summary: These changes will fix executing javascript with any special characters, by making use of the `evaluateJavascript` function on Android 4.4+, and by properly escaping the URI on Android <4.4. Fixes #19611 • Fixes #20365 • Fixes #9749 • Closes #19655 • Closes #12321 This PR supersedes #19655 by patching the same problem in all the places, and fixing it for Android <4.4 as well. Pull Request resolved: #20366 Differential Revision: D9242968 Pulled By: hramos fbshipit-source-id: f2e1abc786ba333dbd8aaa8922e716fd99ec26e0
Summary
When injecting a script to a WebView component via injectedJavaScript prop, if the script contains any comment then it won't work on android (issue: #9749).
Test plan
Create a
WebView
in which we inject a script with a simple comment in it.Code to reproduce
Expected Results
Text on html
h1
element ("Hello!") should be replaced with "Bye!" text.Actual Results
Text on
h1
html element changes on iOS but not on Android. Removing the comment on the js script will fix this issue.