修改 object wkwebview let web \u003d WKWebView(frame: CGRect(x: 0, y: 100, width: view.bounds.size.width, height: view.bounds.size.height - 100)) let js \u003d """\n console.log \u003d (function(oriLogFunc){\n return function(str){\n oriLogFunc.call(console,str);\n //这里,在执行自定义console.log的时候,将str传递出去。\n window.webkit.messageHandlers.log.postMessage(str);\n }\n })(console.log);\n """\n let script \u003d WKUserScript(source: js, injectionTime: .atDocumentStart, forMainFrameOnly: false) web.configuration.userContentController.addUserScript(script) web.configuration.userContentController.add(self, name: "log")


原文地址: https://www.cveoy.top/t/topic/qzqT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录