当我用Electron封装Vditor的时候,出现了以下错误:

当我用Electron封装Vditor的时候,出现了以下错误:


Refused to load the script 'https://unpkg.com/vditor@3.9.0/dist/js/i18n/zh_CN.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval' 'unsafe-inline' data:". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

该回答引用GPTᴼᴾᴱᴺᴬᴵ
这个错误是由于你的应用启用了内容安全策略(Content Security Policy),并且该策略禁止了从https:/unpkg.com/加载的资源的使用。这是为了保护应用程序免受跨站点脚本攻击(XSS)。
·
要解决这个问题,你可以添加一个白名单,允许加载特定的外部资源。可以尝试在你的index.html文件中添加以下内容:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' 'unsafe-eval' https://unpkg.com; img-src 'self' data:; media-src 'self' data:; child-src 'self';">


这将允许从https:/unpkg.com/加载的脚本资源,并允许使用内联脚本和eval函数。同时,也允许加载图片和媒体资源。

请注意,这将会放宽安全策略,所以你需要谨慎地选择允许的资源来源。