You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Related to #195 . The injectedJavaScript prop should allow one to inject JS into a webpage (on iOS, one gets the choice of injecting before or after page load, but React Native doesn't seem to give that amount of granularity). I'd expect to see the page transition from saying "Test before" to "Test after". However, it doesn't produce any change in the web-page at all.
I have tried this both with a static HTML page and dynamic pages loaded over HTTP and HTTPS. I have furthermore tried both with and without NSAllowsArbitraryLoadsInWebContent set to YES.
Reproduction Steps and Sample Code
The UIExplorer WebView examples can be used to reproduce this, or the following minimal example can be copied:
stringByEvaluatingJavaScriptFromString() is a method used for the deprecated UIWebView rather than the up-to-date WKWebView. For a start, this would be better replaced by WKWebViewevaluateJavaScript() (although the former is sync and the latter is async, so that adds differences; but see my final point for a solution anyway).
decidePolicyForNavigationAction() called when the app has "decided whether to allow or cancel the navigation". I fear that any JS executed in here might correspond to the previously-held page rather than being applied to the incoming page, and in any case that it certainly gives no control over whether to inject the JS before beginning, or after completing, page load.
injectedJavaScript would be much better – and ideally – handled by allowing the WKWebView to be initialised with a WKUserContentController that accepts a script to pass into its addUserScript() method. I've had a lot of success with this API.
Is this on the roadmap for the next update, or is help needed in this area?
The text was updated successfully, but these errors were encountered:
Looks like my build/cache must have been screwing up, because I found that the injected JS did begin to work today.
In any case, having been alarmed by the fact that the RN core is still using the hideously outdated UIWebView, I decided to make a macOS fork of the community-favourite CRAlpha/react-native-wkwebview. Until RN do decide to merge that into core, it'll remain as a third-party plugin. But thanks to this fork, making a macOS port will be trivial to get up-to-date if their repo ever does get merged.
My port does not yet expose an API for WKUserContentController.addUserScript(), but it's on my hitlist.
Description
Related to #195 . The
injectedJavaScript
prop should allow one to inject JS into a webpage (on iOS, one gets the choice of injecting before or after page load, but React Native doesn't seem to give that amount of granularity). I'd expect to see the page transition from saying "Test before" to "Test after". However, it doesn't produce any change in the web-page at all.I have tried this both with a static HTML page and dynamic pages loaded over HTTP and HTTPS. I have furthermore tried both with and without
NSAllowsArbitraryLoadsInWebContent
set to YES.Reproduction Steps and Sample Code
The UIExplorer
WebView
examples can be used to reproduce this, or the following minimal example can be copied:Additional Information
react-native-macos v0.16.1
Solution
Will need to revisit this, but I'm beginning to suspect that the native code is outdated. I'm seeing a few problems:
RCTWebView.m passes on the
injectedJavaScript
prop to a call tostringByEvaluatingJavaScriptFromString()
during the decidePolicyForNavigationAction() block.stringByEvaluatingJavaScriptFromString()
is a method used for the deprecatedUIWebView
rather than the up-to-dateWKWebView
. For a start, this would be better replaced byWKWebView
evaluateJavaScript()
(although the former is sync and the latter is async, so that adds differences; but see my final point for a solution anyway).decidePolicyForNavigationAction()
called when the app has "decided whether to allow or cancel the navigation". I fear that any JS executed in here might correspond to the previously-held page rather than being applied to the incoming page, and in any case that it certainly gives no control over whether to inject the JS before beginning, or after completing, page load.injectedJavaScript
would be much better – and ideally – handled by allowing the WKWebView to be initialised with a WKUserContentController that accepts a script to pass into its addUserScript() method. I've had a lot of success with this API.Is this on the roadmap for the next update, or is help needed in this area?
The text was updated successfully, but these errors were encountered: