unity3d - Chrome 扩展:拒绝加载脚本,因为它违反了以下内容安全策略指令:“script-src 'self'”
问题描述
我正在尝试将游戏作为扩展程序添加到 Chrome 网上应用店,但我遇到了一些问题。游戏是用 Unity3D 制作的。
错误:
拒绝加载脚本“blob:chrome-extension://laacabdjcfgafjkeclplanjohdbpapgn/88f06275-2339-4218-a7c4-ab954cbaafdc”,因为它违反了以下内容安全策略指令:“script-src 'self'”。请注意,'script-src-elem' 没有明确设置,因此 'script-src' 用作后备。
触发错误的代码:
function f() {
return d("frameworkUrl").then(function(e) {
var t = URL.createObjectURL(new Blob([e], {
type: "application/javascript"
}));
return new Promise(function(e, n) {
var r = document.createElement("script");
r.src = t, r.onload = function() {
var n = unityFramework;
unityFramework = null, r.onload = null, URL.revokeObjectURL(t), e(n)
}, document.body.appendChild(r), c.deinitializers.push(function() {
document.body.removeChild(r)
})
})
})
}
确切的行:
}, document.body.appendChild(r), c.deinitializers.push(function() {
该扩展使用Manifest Version 3。没有使用外部脚本/资源。我尝试了几天来解决这个问题,但我无法做到。
有没有人尝试过这样的事情并且可以帮助我?或者,也许你有一个想法……我愿意接受。
谢谢!:)
解决方案
您的代码尝试将外部脚本添加t
到扩展页面。出于安全原因,它在清单 V3 中在概念上是被禁止的。实际上,CSP 指令script-src 'self'
禁止这样做。
https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#content-security-policy
您也不能在内容脚本中执行外部代码。
https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#executing-arbitrary-strings
如果要执行外部代码,可以在沙箱页面中执行。
https://developer.chrome.com/docs/extensions/mv3/manifest/sandbox/
推荐阅读
- amazon-web-services - 确定谁创建了特定 AWS 资源
- node.js - 显示无法找到 package.json。Node.js 启动时可能会出现问题。验证 package.json 是否有效或将代码放在名为 server.js 或 app.js 的文件中
- node.js - npm install 时不同的节点版本冲突
- java - 如何为使用apache-poi java将数据写入word文档的类编写单元测试?
- c# - DoubleClick 在 DataGrid 和 DataTemplate 中触发
- azure-active-directory - MS Graph:获取用户角色和手机
- java - 启动 JavaFX 应用程序时的内部 NPE
- amazon-redshift - 如何在 Redshift 中查询架构信息?
- java - 从 WildFly8 / jdk8 迁移到 WildFly14 / jdk11 后 WebService 客户端中的 java.net.SocketTimeoutException
- flutter - 由于我的代码中的 setState(),我的动画滞后