WKWebView.evaluateJavaScript(_:completionHandler:) must be used from main thread only
Opened this issue · 2 comments
const excute_webview = async (form_link) => {
await InAppBrowser.openWebView({
url: form_link,
//if true, the browser will be presented after the page is loaded, if false, the browser will be presented immediately.
isPresentAfterPageLoad: true,
});
await InAppBrowser.addListener("urlChangeEvent", async (event) => {
await InAppBrowser.executeScript({
code: `alert("hi")`
});
});
await InAppBrowser.addListener("closeEvent", async (event) => {
await InAppBrowser.removeAllListeners();
});
};
above code good work on android.
but not work on ios.
and �there's an error like below
Main Thread Checker
func executeScript(script: String, completion: ((Any?, Error?) -> Void)? = nil) {
webView?.evaluateJavaScript(script, completionHandler: completion)
}
WKWebView.evaluateJavaScript(_:completionHandler:) must be used from main thread only
and also error like below
Main Thread Checker: UI API called on a background thread: -[WKWebView evaluateJavaScript:completionHandler:]
PID: 71027, TID: 6120033, Thread name: (none), Queue name: bridge, QoS: 0
Backtrace:
4 CapgoInappbrowser 0x0000000102390870 $s17CapgoInappbrowser19WKWebViewControllerC13executeScript6script10completionySS_yypSg_s5Error_pSgtcSgtF + 352
5 CapgoInappbrowser 0x0000000102377ff0 $s17CapgoInappbrowser18InAppBrowserPluginC13executeScriptyySo13CAPPluginCallCF + 320
6 CapgoInappbrowser 0x00000001023780b8 $s17CapgoInappbrowser18InAppBrowserPluginC13executeScriptyySo13CAPPluginCallCFTo + 52
7 Capacitor 0x0000000102543788 $s9Capacitor0A6BridgeC12handleJSCall4callyAA0D0V_tFyyYbcfU0_ + 856
8 Capacitor 0x000000010254417c $sIegh_IeyBh_TR + 48
9 libdispatch.dylib 0x00000001029b7ec4 _dispatch_call_block_and_release + 24
10 libdispatch.dylib 0x00000001029b973c _dispatch_client_callout + 16
11 libdispatch.dylib 0x00000001029c1a30 _dispatch_lane_serial_drain + 916
12 libdispatch.dylib 0x00000001029c2774 _dispatch_lane_invoke + 420
13 libdispatch.dylib 0x00000001029cf1a8 _dispatch_root_queue_drain_deferred_wlh + 324
14 libdispatch.dylib 0x00000001029ce604 _dispatch_workloop_worker_thread + 488
15 libsystem_pthread.dylib 0x0000000100e0f814 pthread_wqthread + 284
16 libsystem_pthread.dylib 0x0000000100e0e5d4 start_wqthread + 8
Main Thread Checker: UI API called on a background thread: -[WKWebView evaluateJavaScript:completionHandler:]
PID: 71027, TID: 6120033, Thread name: (none), Queue name: bridge, QoS: 0
Backtrace:
4 CapgoInappbrowser 0x0000000102390870 $s17CapgoInappbrowser19WKWebViewControllerC13executeScript6script10completionySS_yypSg_s5Error_pSgtcSgtF + 352
5 CapgoInappbrowser 0x0000000102377ff0 $s17CapgoInappbrowser18InAppBrowserPluginC13executeScriptyySo13CAPPluginCallCF + 320
6 CapgoInappbrowser 0x00000001023780b8 $s17CapgoInappbrowser18InAppBrowserPluginC13executeScriptyySo13CAPPluginCallCFTo + 52
7 Capacitor 0x0000000102543788 $s9Capacitor0A6BridgeC12handleJSCall4callyAA0D0V_tFyyYbcfU0 + 856
8 Capacitor 0x000000010254417c $sIegh_IeyBh_TR + 48
9 libdispatch.dylib 0x00000001029b7ec4 _dispatch_call_block_and_release + 24
10 libdispatch.dylib 0x00000001029b973c _dispatch_client_callout + 16
11 libdispatch.dylib 0x00000001029c1a30 _dispatch_lane_serial_drain + 916
12 libdispatch.dylib 0x00000001029c2774 _dispatch_lane_invoke + 420
13 libdispatch.dylib 0x00000001029cf1a8 _dispatch_root_queue_drain_deferred_wlh + 324
14 libdispatch.dylib 0x00000001029ce604 _dispatch_workloop_worker_thread + 488
15 libsystem_pthread.dylib 0x0000000100e0f814 _pthread_wqthread + 284
16 libsystem_pthread.dylib 0x0000000100e0e5d4 start_wqthread + 8
i tried everything
please help me..
Thanks for the report this should be fixed is latest version
I have the same problem when I use this code (version 6.9.22):
await InAppBrowser.openWebView({
title: 'Test',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
url: 'localhost:4200',
toolbarType: ToolBarType.BLANK,
isPresentAfterPageLoad: false,
disableGoBackOnNativeApplication: false,
ignoreUntrustedSSLError: true,
isInspectable: true
});
await InAppBrowser.addListener("browserPageLoaded", () => {
InAppBrowser.postMessage({detail: {"message": "Test"}}); // <- This is the cause of the problem
});
Thank you