【发布时间】:2014-05-17 10:41:12
【问题描述】:
我正在尝试使用 Dart 和 Polymer 构建一个应用程序。但是聚合物脚本似乎在 web_components/platform.js:32 中使用了 eval()。有没有人设法做到这一点?我尝试更改 CSP,但这首先有所帮助。
谁有一个可行的例子?
问候和感谢 罗伯特
编辑
manifest.json:
{
"name": "Animatr app",
"version": "1",
"author": "Robert Hartung",
"manifest_version": 2,
"icons": {"128": "animatr_icon.png"},
"app": {
"background": {
"scripts": ["background.js"]
}
},
"content_security_policy": "script-src 'self' unsafe-inline;"
}
main.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Animatr app</title>
<link rel="stylesheet" href="animatr_chrome_app.css">
<link rel="import" href="packages/polymer/polymer.html">
</head>
<body>
<script src="packages/chrome/bootstrap.js" defer></script>
<script src="my_chrome_app.dart" type="application/dart;component=1"></script>
</body>
</html>
错误:
Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in 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. (chrome-extension://ofkfcbfhgkoglbgldcdokficikimdjji/packages/web_components/platform.js:32)
Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self' chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.
pubspec.yaml:
name: animatr_app
description: A sample Chrome packaged application
dependencies:
chrome: any
polymer: any
transformers:
- chrome
- polymer:
entry_points:
- app/animatr_chrome_app.html
csp: 'true'
应用无法正确识别聚合物元素。
【问题讨论】:
-
能否请您添加更多信息(错误消息,pubspec.yaml,包结构,manifest.json,...)
-
它在 Dartium 上运行良好吗? (无需构建到 js)
-
我只尝试过纯飞镖和铬。从飞镖编辑器启动应用程序。
-
我编辑了我的帖子以向您展示代码。
-
我不知道细节,但是需要一个名为 Vulcanizer 的 Polymer 工具来使 Polymer CSP 兼容。我认为这个想法是将所有组件连接到一个包含中,以避免需要动态包含更多 JavaScript。
标签: dart google-chrome-app dart-polymer