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
Error evaluating injectedJavaScript: This is possibly due to an unsupported return type. Try adding true to the end of your injectedJavaScript string. #341
Comments
What worked for us was this:
|
That didn't work 😢 |
I've noticed that if I pause between one call to |
Throttling the calls to this.injectJavaScript = throttle(this.injectJavaScript.bind(this), 500); |
@EgidioCaprino's solution worked for me. I had to stop using the |
This problem still occurs for us 😢 |
See your JS code carefully, this error is due to the fact that WebView can not execute JS code! |
The same code was working with |
Android or iOS ? |
just upgraded from 2.10 to the current latest and started running into this. The injection seems a wee bit more unreliable in general after the upgrade. (iOS) |
This seems to happen when you inject code too early before webview is loaded, but I'm not sure |
Facing it with some form submission .
|
Fixed using a timer.
|
When I inject stuff inside the webview i'll always wrap it inside a function and instantly execute it. It allows me to avoid wrong return types: (function(lol){
//do stuff
})() |
@legion-zver is right. Try running that same code in a Web browser console and verify that it can execute. There is likely a minor syntax error. |
i have the same issue , The same code was working with WebView imported from react-native,Who has a good solution? |
This is really late, but for anyone else stuck on this issue and having problems finding a solution, for me the issue was that in the original react-native WebView I could just call
You will see this message for any JS error thrown by the webview. By updating your TL;DR => Replace |
In my case I replaced |
@sillysachin's solution worked for me, and even with a large injection on a very slow simulator, using |
This bug is present in iOS <= 9.2. For recent releases this bug is not present. |
using |
try and catch works fine, if you are adding an event to an element that does not exist you are gonna get (Error evaluating injectedJavaScript: This is possibly due to an unsupported return type. Try adding true to the end of your injectedJavaScript string. for example I used this:
|
react-native-webview outputs the message "Please add true to the end of the inserted JavaScript string" regardless of the error that occurred in In most cases, you will see the error "WKWebView was invalidated." |
It is not because inject code too early before webview is loaded, the reason is inject code too early before |
In our error, we were trying to inject during |
issue still (some time)
|
Had this problem, realized it was a function in my code that was looping indefinitely within the webview. So don't forget to check if that's happening. |
Amazing still issue after 3 years. Crazy. |
Yeah I'm having this issue as well. I've noticed it only happens when I try to call |
this could be an alternative
|
Except it doesn't because you didn't interpolate the string in the injected JS. Replace ' with ` and you're golden. |
Hello,
We're trying to migrate from
react-native
WebView
. Replacingimport { WebView } from 'react-native'
withimport { WebView } from 'react-native-webview'
gives us this error when the component is mounted:I've tried to add
; true
or; return true
at the end of the injected script but we still get the same error.Do you know how we can fix it or identify the underlying problem?
The text was updated successfully, but these errors were encountered: