WKWebview.evaluateJavaScript doesn't return when disconnect the internet.

Below is my code:

let loginButton = "document.getElementById('loginButton').click()"
webView.evaluateJavaScript(loginButton) { result, error in 
print(result, error)
}

It works fine when the device has internet. But before calling this func, I turn off the internet, the func is called but nothing returned.

Can I set a timeout for this func or get a callback error from anything to know there is an error. Thanks.