chore(plugin-style): 插件样式注入加自检 + 复盘写进 DESKTOP_PITFALLS
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 2m24s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 2m24s
这次事故(CSP nonce 让插件动态 <style> 被整段丢弃)已修,补两道防线,避免再静默复发: - src/runtime-plugin-loader.js:注入后检查 node.sheet;head 场景为 null 时自动改挂 body; 仍为 null 就写 _boot.log 并 console.warn(不再静默丢样式) - src/storage-file.js:对外暴露 logLine(),供其它模块写 _boot.log 做诊断 - docs/DESKTOP_PITFALLS.md:新增「2026-11-27 插件样式全丢复盘」,写清 nonce → unsafe-inline 失效 的链条、同根因的历史(v3.26.7 / v3.26.9),以及四条铁律(index.html 禁内联、样式自检、 改 CSP 或 index.html 必须桌面端实机验面板)
This commit is contained in:
1 parent
9210bc3d0b
commit
487eeadf1f
4 files changed
+38
-2
No files matched your search
@@ -54,6 +54,19 @@
|
||||
// 与单文件插件共用同一套「自注册」契约,区别只是多读一个 manifest 和可选 styles.css。
|
||||
const styleNodes = {}
|
||||
const pendingStyles = {}
|
||||
// v3.26.109 教训(两次踩坑):
|
||||
// 1) WKWebView 下插到 <head> 的 <style> 可能 sheet === null,不参与样式计算(v3.26.7);
|
||||
// 2) 页面里只要有带 CSP nonce 的内联块,'unsafe-inline' 就失效,没有 nonce 的动态
|
||||
// <style> 会被整段丢弃(v3.26.9、以及 v3.26.109 又在 index.html 写内联块复现)。
|
||||
// 所以:挂到 body(更稳),挂完当场自检 sheet,不生效就写进 _boot.log —— 让问题可见,而不是静默丢样式。
|
||||
function checkStyleSheet (id, node) {
|
||||
try {
|
||||
if (!node || node.sheet) return
|
||||
const msg = 'plugin-style-no-sheet id=' + String(id)
|
||||
try { const st = global.IWBStorageFile; if (st && st.logLine) st.logLine(msg) } catch (e) { /* ignore */ }
|
||||
try { if (global.console && global.console.warn) global.console.warn('[iwb] ' + msg + '(样式未参与计算:检查 CSP nonce / 挂载位置)') } catch (e) { /* ignore */ }
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
function applyStyle (id, css) {
|
||||
if (!css) return
|
||||
try {
|
||||
@@ -64,7 +77,10 @@
|
||||
node.setAttribute('data-plugin', String(id))
|
||||
node.textContent = String(css)
|
||||
doc.head.appendChild(node)
|
||||
// 自检:WKWebView 下 head 里的 style 可能 sheet = null(不参与样式计算)→ 自动改挂 body
|
||||
if (!node.sheet) { try { (doc.body || doc.head).appendChild(node) } catch (e2) { /* ignore */ } }
|
||||
styleNodes[id] = node
|
||||
checkStyleSheet(id, node)
|
||||
} catch (e) { /* 样式失败不影响脚本 */ }
|
||||
}
|
||||
function applyStyleFor (id) {
|
||||
|
||||
Reference in new issue
Block a user