Inline script triggers CSP error in chrome extension
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 42/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- typescript
调研方向
首先定位 injectVueHookToIframe,并在使用 Manifest V3 CSP 的 Chrome 扩展中复现该问题。跟踪内联脚本的创建过程,并确定一种可避免 CSP 违规的外部代码注入方案;当 Vue devtools iframe hook 在没有报告的错误的情况下正常工作时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
When using vite plugin vue devtools to develop a chrome extension page, the extension reported the following error:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' http://localhost: * http://127.0.0.1: *". Either the 'unsafe-inline' keyword, a hash ('sha256-FhCISuQOxB+ZEYLZlvQzFWx4//lRqFQPUeFSEkdvsT0='), or a nonce ('nonce-...') is required to enable inline execution.
It seems to be triggered by the following code:
function injectVueHookToIframe(iframe) {
if (iframe.__vdevtools__injected) return
try {
iframe.__vdevtools__injected = true
const inject = () => {
try {
iframe.contentWindow.__VUE_DEVTOOLS_IFRAME__ = iframe
const script = iframe.contentDocument.createElement('script')
script.textContent = `;(${detectIframeApp.toString()})(window, true)`
iframe.contentDocument.documentElement.appendChild(script)
script.parentNode.removeChild(script)
} catch (e) {}
}
inject()
iframe.addEventListener('load', () => inject())
} catch (e) {}
}
The problem is:
// This line attempts to inject inline script blocks
script.textContent = `;(${detectIframeApp.toString()})(window, true)`
iframe.contentDocument.documentElement.appendChild(script)
In chrome extension Manifest V3, there is no way to declare inline script as safe, CSP will prevent code injection and throw errors.
Can the injection method of the code be changed to external code?
- 主要语言
- TypeScript
- 星标
- 2.9k
- 派生
- 291
- 平均合并
- 4 天 6 分钟
- 30 天内合并 PR
- 27
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
vuejs/devtools 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 69/100
维护者通常 3 天内回复
-
Upgrade Electron to fix ZIP extraction on Node.js 26可能已有人在做 @ondrhn 于 54 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 3 天内回复
-
On the landing site, the "Developer experience" card is redundant可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 3 天内回复
-
难度 5/5 一周以上 新手友好度 18/100
维护者通常 3 天内回复
相似的 Issue
-
desktop v3 windows
难度 2/5 1-3 小时 新手友好度 75/100
esengine/DeepSeek-Reasonix#15016 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
readest/readest#7413 · 1 条评论 ·
维护者通常 1 天内回复
-
enhancement good first issue priority: medium size: XS
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
content triage
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
eliasstravik/herdr-projects#788 ·