Commit Graph
2 Commits
Author SHA1 Message Date
joywayerandClaude Opus 4.7 a1c5883cc5 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>
2026-06-23 02:04:46 +08:00
joywayer 65505b0a79 Phase 1.9:BridgedWebView 封装 WKWebView + JS 注入 + BridgeBus
WebContainerViewController(Phase 1.10)的视图层依赖项:把 WKWebView 配置 /
WVJB.js 注入 / 桥总线 / scrollView 契约配置 4 件事一锅端打包成单一 UIView,
后续大厅 / 子游戏 / 弹层 VC 直接 add 进自己的内容区即可。

- 新增 ylgamehall/Source/WebView/BridgedWebView.swift
  - @MainActor final class,继承 UIView
  - 内含 public let webView: WKWebView 与 public let bridge: BridgeBus
  - init() 全自动:
    - WKWebViewConfiguration 按契约 §4.1:
      defaultWebpagePreferences.allowsContentJavaScript = true(iOS 14+
      现代 API,替代已弃用的 preferences.javaScriptEnabled)、
      javaScriptCanOpenWindowsAutomatically = NO、minimumFontSize = 10、
      allowsInlineMediaPlayback = true、processPool = SharedProcessPool.shared
    - 用 WKUserScript(.atDocumentStart) 把 WebViewJavascriptBridge.js 注入
      所有加载的 H5 页面,确保 H5 业务代码运行前 bridge 已就绪
    - 创建 BridgeBus,自动向 controller 注册 WVJBHandler 通道
    - scrollView:bounces=NO / isScrollEnabled=NO(契约硬约束,漏则 H5
      上下滑动失控)/ contentInsetAdjustmentBehavior=.never / 双向无指示器
    - WebView 撑满 self,自动布局
  - SharedProcessPool 命名空间:跨 WebView 共享 WKProcessPool,Cookie /
    资源缓存复用,启动加速(Design §3.5)
- BuildProject 通过,下一步 Phase 1.10 WebContainerViewController 用
  BridgedWebView 嵌入 + 16:9 letterbox + 加载 lobbyIndex
2026-06-22 00:19:51 +08:00