Skip to content
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

WKWebView.evaluateJavaScript(_:completionHandler:) must be used from main thread only #181

Open
LeeSangMin12 opened this issue Aug 22, 2024 · 1 comment

Comments

@LeeSangMin12
Copy link

 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..

@riderx
Copy link
Contributor

riderx commented Aug 30, 2024

Thanks for the report this should be fixed is latest version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants