javascript - Dart 拒绝加载 JS

标签 javascript dart google-chrome-app content-security-policy

在我的 Dart amount 网页中,此脚本:

<script src="https://test.net/test/test.js"></script>  

但是当您启动应用程序时,它会出现以下错误:

Refused to load the script 'https://test.net/test/test.js' because it violates the following Content Security Policy directive: "default-src 'self' chrome-extension-resource:". Note that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.

我还在 list 中设置了内容安全策略,但没有任何结果:

"content_security_policy": "script-src 'self' https://test.net/test/"

有人知道如何解决吗?

编辑

这个答案Loading external javascript in google chrome extension在 Dart 中不起作用。

list :

..."permissions":["tabs","https://test.net/test/"],
"content_security_policy": "script-src 'self' https://test.net/test/; object-src 'self'",
"content_scripts": [
{
  "js": ["https://test.net/test/test.js"]
}
]...

代码:

JsObject spark=context['spark'];
print(spark);
spark.callMethod('login',["{username: 'test@email.com', password: 'test'}"]);

结果:

null

Exception: The null object does not have a method 'callMethod'.

Dart 不支持动态脚本注入(inject):

Will there be a dynamic code injection for dart?

那么如何更改内容安全策略?

编辑2

当我安装该应用时,Chrome 报告此错误:

enter image description here

最佳答案

在 Chrome 软件包应用中,您不能使用“content_scripts”“content_security_policy”“tabs” 字段。

Dart 也不支持动态脚本注入(inject)。正如这里所解释的:

Will there be a dynamic code injection for dart?

要使用JS代码必须将其保存在本地,将其导入到您的html代码中:

<script src="test.js"></script>

并使用库 dart:js与js代码交互,例如:

  test=context['test'];
  test.callMethod("login",["var1","var2",...,callback]);

关于javascript - Dart 拒绝加载 JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30809498/

相关文章:

javascript - 更改 switch 语句以包含 mp4 和 ogg 文件

android-studio - flutter 应用栏中不需要的操作按钮

redux - 如何在带有 Redux 的 Flutter 中显示 snacker(或推送另一个页面)?

javascript - Chrome 打包应用程序中的 JSON 模式验证

javascript - 删除 Javascript blob?

javascript - 如何从 JavaScript 获取 HTTP 状态

javascript - ASP CustomValidator,错误后前进到回发

javascript - node.js 嵌套 http req 对象未定义 - bodyParser.urlencoded({ 扩展 : true } not working

dart - Flutter中Column的 child 之间的空间

sockets - 使用Chrome应用程序套接字API检测远程计算机上的端口是否打开