fix: CSP nonce 导致动态 style 全丢(插件样式失效)v3.26.9 / promptlib 1.4.5
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 2m52s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 2m52s
This commit is contained in:
1 parent
a3edc81f55
commit
5f8f4d229f
22 files changed
+135
-43
No files matched your search
@@ -62,8 +62,11 @@
|
||||
if (styleNodes[id] && styleNodes[id].parentNode) styleNodes[id].parentNode.removeChild(styleNodes[id])
|
||||
const node = doc.createElement('style')
|
||||
node.setAttribute('data-plugin', String(id))
|
||||
// v3.26.8:CSP 带 nonce 时,没有 nonce 的内联 <style> 会被整段丢弃(实测 sheet=null)
|
||||
try { const n0 = doc.querySelector('style[nonce], link[nonce]'); const nv = n0 ? String((/** @type {any} */ (n0)).nonce || n0.getAttribute('nonce') || '') : ''; if (nv) node.setAttribute('nonce', nv) } catch (e) { /* ignore */ }
|
||||
node.textContent = String(css)
|
||||
doc.head.appendChild(node)
|
||||
// v3.26.7:WKWebView 里动态插入 <head> 的 <style> 可能不生效(sheet=null),统一挂到 body
|
||||
;(doc.body || doc.head).appendChild(node)
|
||||
styleNodes[id] = node
|
||||
} catch (e) { /* 样式失败不影响脚本 */ }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user