在我的 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):
那么如何更改内容安全策略?
编辑2
当我安装该应用时,Chrome 报告此错误:
最佳答案
在 Chrome 软件包应用中,您不能使用“content_scripts”
、“content_security_policy”
和 “tabs”
字段。
Dart 也不支持动态脚本注入(inject)。正如这里所解释的:
要使用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/