计划进度:M2 完成、R-02(V2 file:// 跨域)关闭

- 01_任务分解WBS:M2 标记完成(13 任务),新增 M2 任务明细块与决策/偏差记录
- 03_风险登记册:R-02 关闭(setPathAllowingUniversalAccess 方案 + 真机复测 OK)
- 框架 §7.3:file:// 跨域改为已验证的具体方案(setPathAllowingUniversalAccess),保留 onInterceptRequest 回退
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
lanterngamescn
2026-06-25 18:43:18 +08:00
parent 2100faaef7
commit 40b8c2e91c
3 changed files with 34 additions and 4 deletions
@@ -535,9 +535,14 @@ export struct GenericWebContainer {
- `settings` 的 6 方法、`getWebdata`/`gamebackkeydown`/`backgameData` 三个直调函数严格照《契约规范》§11.3。
- **回传上层**:用路由返回值或 `emitter` 事件把 `data` 投递回打开它的 Bridge 容器,由后者 `callHandler('getWebdata', data)`(复刻 Android 结果码 101 语义)。
### 7.3 file:// 跨域
### 7.3 file:// 跨域V2 已验证,2026-06-25
H5 以 `file://` 加载并请求本地/远程资源。HarmonyOS 侧采用官方"Web 页面跨域解决方案":用 `onInterceptRequest` 自定义本地资源响应,或为本地页配置自定义协议/响应头,避免 file 同源限制。**对 H5 透明**
H5 以 `file://` 加载并请求本地资源时,ArkWeb 默认按 CORS 拦截(file 页面 origin 为 `null`,且 `file` 不在允许跨域的 scheme 列表)——**T-M2-08 真机首测确认了这一拦截**(`Access to fetch ... blocked by CORS policy`
**采用的解决方案(落地、对 H5 透明)**:在 `onControllerAttached` 调用
`WebviewController.setPathAllowingUniversalAccess([<filesDir>/tsgames])`,把资源根加入"允许跨域访问"白名单——该路径下的 `file://` 资源即放开同源限制,H5 的 XHR/fetch 正常工作。约束:路径须为 `filesDir`/`resourceDir` 子目录、与用户文件隔离;一旦设置,`file` 协议仅限访问白名单内资源(覆盖 `fileAccess` 行为)。
> 此方案比通用的 `onInterceptRequest`/`WebSchemeHandler` 代理更简(无需逐请求拦截、无需改首页 scheme),是 HarmonyOS 官方《Web 页面跨域解决方案·本地资源跨域》的推荐做法。若未来遇白名单不可用的边缘场景,仍可回退 `onInterceptRequest` 自定义响应。**对 H5 始终零改动**。
### 7.4 屏幕方向(横屏项目)