Get page loaded Event on Webview

孤街浪徒 提交于 2019-12-24 09:19:23

问题


Example URL: https://unifiedportal-mem.epfindia.gov.in/memberinterface/ From this click on Forgot Password then Input UAN as: 101010101010 type captcha and submit.

How to obverse page didFinish on this? How to get the message "UAN is not Active" which comes after loading.

This didFinish function of webView doesn't work in this scenario as page is already loaded.

    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!{
}

Tried below way but no response. Got this

Error Domain=WKErrorDomain Code=5 "JavaScript execution returned a result of an unsupported type" UserInfo={NSLocalizedDescription=JavaScript execution returned a result of an unsupported type}

let s = """
var open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
    this.addEventListener("load", function() {
        var message = {"status" : this.status, "responseURL" : this.responseURL}
        webkit.messageHandlers.handler.postMessage(message);
    });
    open.apply(this, arguments);
};
"""
                        weakSelf.webView.configuration.userContentController.removeScriptMessageHandler(forName: "myInterface") // to delete existing
                        weakSelf.webView.configuration.userContentController.add(weakSelf as WKScriptMessageHandler, name: "myInterface")
                        weakSelf.webView?.evaluateJavaScript(s, completionHandler: {(string,error) in
                            print(error ?? "no error")
                        })

来源:https://stackoverflow.com/questions/52928183/get-page-loaded-event-on-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!