-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[InAppWebview]: window.flutter_inappwebview.callHandler is not a function #218
Comments
I get this error TypeError: undefined is not an object (evaluating 'window.flutter_inappbrowser.callHandler') on running the below example
|
@ositano that's because it is not |
@pichillilorenzo thank you, I have changed it as you pointed, but now it crashes the app. I am running on iOS simulator. When i tried running using _callHandler as mentioned on the issue @OPY-bbt referenced I get TypeError: window.flutter_inappwebview._callHandler is not a function |
|
@ositano please post the error log you get! For iOS, open launch your app with Xcode and take the logs from it |
@pichillilorenzo i was unable to run from xcode |
@ositano thats because you are using an Xcode version below 11. This plugin, as written in the Requirements section of the README.md file and in the official documantation, requires Xcode >= 11. Just update Xcode and it should work. |
@pichillilorenzo see this |
@ositano Please create a new issue. Don't ask questions that are irrelevant to the title |
|
I also have the same issue in Android, but in iOS it working fine. Do we have any workaround yet? |
it's not working in Android 9-,but in Android 10 and iOS it working fine. |
Any news? |
Looking for help for this problem, Android 8 is not working |
求解决。。。官方不支持选择文件,这个还有不少bug。心好累。。。。 |
String js = InAppWebView.consoleLogJS.replaceAll("[\r\n]+", "");
换到onPageFinished里面就好使了 |
my workaround: const message = "value";
if (window.flutter_inappwebview.callHandler) {
window.flutter_inappwebview.callHandler('handlerName', message);
} else {
window.flutter_inappwebview._callHandler('handlerName', setTimeout(function(){}), JSON.stringify([message]));
} |
I have the same issue.
Maybe this is the problem |
The cause of this issue is that only onPageStarted callback sets callHandler JS. diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java
index 84ad883..3276175 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebView/InAppWebViewClient.java
@@ -223,7 +223,8 @@ public class InAppWebViewClient extends WebViewClient {
view.clearFocus();
view.requestFocus();
- String js = InAppWebView.platformReadyJS.replaceAll("[\r\n]+", "");
+ String js = JavaScriptBridgeInterface.flutterInAppBroserJSClass.replaceAll("[\r\n]+", "");
+ js += InAppWebView.platformReadyJS.replaceAll("[\r\n]+", "");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.evaluateJavascript(js, (ValueCallback<String>) null); |
I have tried everything but I'm still stucked on the original problem: callHandler is not a function... on Dart side I use this that should inject the handler onWebViewCreated: (InAppWebViewController controller) {
on HTML side I use this and I get the error:
Just an exampleAny idea? |
anyone solved this? |
I solved this issue by adding these code: ...
String _js = '''
if (!window.flutter_inappwebview.callHandler) {
window.flutter_inappwebview.callHandler = function () {
var _callHandlerID = setTimeout(function () { });
window.flutter_inappwebview._callHandler(arguments[0], _callHandlerID, JSON.stringify(Array.prototype.slice.call(arguments, 1)));
return new Promise(function (resolve, reject) {
window.flutter_inappwebview[_callHandlerID] = resolve;
});
};
}
''';
...
InAppWebView(
...
onWebViewCreated: (controller) {
controller.addJavaScriptHandler(
...
);
},
onLoadStop: (controller, url) {
controller.evaluateJavascript(source: _js);
},
...
); hope this help. 😁 |
here |
how can i solve it? head big |
Confirmed @WangPe1n 's fix did the trick. |
@WangPe1n Your code is valid!!! |
@WangPe1n workaround not working. I'm still getting the same error |
@rajashah33 Copy that js fragment to |
@WangPe1n you save me!!! |
@cijianzy it should already work with the latest version without any workaround |
I am using
and I only got the callback it to work when using @WangPe1n 's workaround. Worked on ios but did not work on android except with this workaround. |
@kiwiidb if you have problems, please post a new issue with a code example to be able to reproduce that behavior. It should already work with version 5+. |
This bug still occurs for me. I'm going to post a new issue in the next few days. |
You can use this code to prevent the crash error in the javascript level. I add try-catch to prevent the crash and allow flutter handle the exception itself. `String _js = ''' result = await webController.evaluateJavascript(source: _js) ?? "failed"; |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue. |
Environment
Flutter version: 1.10.15
Plugin version: ^2.1.0+1
Android version: 9
iOS version:
Xcode version:
Device information:
Description
I use demo to load url, but get javascript error when click div.
I/flutter (27593): Uncaught TypeError: window.flutter_inappwebview.callHandler is not a function
The text was updated successfully, but these errors were encountered: