Phase 9.2:H5ErrorRelay 把 H5 异常中继到原生 print
零修改 H5(原则 A):WKUserScript .atDocumentStart 在业务 JS 跑前 hook 三类异常源: - `console.error(...)`:保留原函数链式调用 + 转发 args - `window.onerror`:onmessage / filename / lineno / colno / error.stack - `unhandledrejection`:reason + reason.stack 走独立的 webkit.messageHandlers.h5error 通道(与 WVJB 不同 channel,不冲突)。 原生侧 MessageProxy weak target 切断 retain cycle。仅 BridgedWebView 安装 (大厅+子游戏),OverlayViewController 是第三方外链,不挂。 开发期价值:H5 出错时 Xcode console 直接能看到 "[H5 onerror] ... at xxx.js:42:8", 减少调试盲点。生产期 print 走 OSLog,对体积/性能影响极小。 新增: - Source/Bridge/H5ErrorRelay.swift(@MainActor singleton) 接入: - BridgedWebView.init:H5ErrorRelay.shared.install(into:) 在 WVJB 之后 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
5885f97715
commit
a1c5883cc5
@@ -42,6 +42,11 @@ public final class BridgedWebView: UIView {
|
||||
print("[BridgedWebView] ERROR: WebViewJavascriptBridge.js 未在 Bundle 找到")
|
||||
}
|
||||
|
||||
// ── H5 错误中继(Phase 9.2,原则 A 零修改 H5)─────────────
|
||||
// 把 console.error / window.onerror / unhandledrejection 通过独立
|
||||
// 的 webkit.messageHandlers.h5error 桥到原生 print,开发期减少盲点。
|
||||
H5ErrorRelay.shared.install(into: configuration.userContentController)
|
||||
|
||||
// ── 创建 WKWebView + BridgeBus ─────────────────────────
|
||||
let webView = WKWebView(frame: .zero, configuration: configuration)
|
||||
let bridge = BridgeBus(webView: webView,
|
||||
|
||||
Reference in New Issue
Block a user