类似的问题已经存在了一段时间,也许有人知道今天堆栈的答案。理想情况下保留可调试性......
我有一个Dart应用程序,它在Polymer / Dart中实现GUI,在Chrome / Dart中实现后端。这两个部分都运行良好(非常感谢)现在我正在尝试将它们联系在一起并调试任何问题。统一的应用程序遇到了一波CSP错误,所以我整理了一个小小的测试用例。网上有Dart / Polymer / CSP建议,但随着事态的发展而变化,很难看到当前的最佳实践。以下是测试用例:
的manifest.json
{
"manifest_version": 2,
"name": "Test Case",
"version": "0.3",
"icons": {"128": "dart_icon.png"},
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"app": {
"background": {
"scripts": ["background.js"]
}
},
"permissions": [ "usb"
, { "usbDevices": [ {"vendorId": 1027, "productId": 24597} ] }
, { "fileSystem": [ "write", "retainEntries", "directory" ] }
]
}
background.js
chrome.app.runtime.onLaunched.addListener(function(launchData) {
chrome.app.window.create('testwrap.html', {
'id': '_myMainWindow',
'bounds': {'width': 800, 'height': 500 }
});
});
testwrap.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>PolyChrome</title>
<link rel="import" href="packages/polymer/polymer.html">
<link rel="import" href="clickcounter.html">
</head>
<body>
<h1>Testing...</h1>
<p>in the test directory...</p>
<div id='container_id'>
<p id='text_id'>The log is here.</p>
</div>
<div id='div2'>
<click-counter></click-counter>
</div>
<script type='application/dart' src='testwrap.dart'></script>
</body>
</html>
testwrap.dart
import 'dart:html';
import 'package:polymer/polymer.dart';
export 'package:polymer/init.dart';
//----------------------------------------
@whenPolymerReady
void mainStartup() {
querySelector("#text_id").text = 'Running';
}
click-counter元素是Dart / Polymer页面中的标准代码。
yaml包含$ dart2js,可能未使用(?)或者可能有两个csp:true行不正确?
pubspec.yaml
name: polyChrome
description: Chrome App with Polymer
dependencies:
chrome: ^0.7.0-dev1
code_transformers: any
core_elements: any
paper_elements: any
polymer: any
transformers:
- polymer:
entry_points:
- web/testwrap.html
csp: 'true'
- $dart2js:
csp: 'true'
checked: 'true'
CSP错误消息(完全相同):
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.
令人困惑的是,尽管有错误消息,测试应用程序似乎仍能正常工作,但是在启动时会有更大的测试冻结 - 无法忽略这些消息。
较大的测试会从
中显示错误消息Zone zone = await initPolymer();
消息有些不透明(my_clock是一个测试聚合物组件,100%作为Web应用程序工作):
Breaking on exception: Unsupported operation: Unsupported uri scheme chrome-extension for library LibraryMirror on 'my_clock'.
答案 0 :(得分:2)
这甚至不是部分答案,但对其他人可能有所帮助......
csp线有一个常见的拼写错误。不要写:
csp: 'true'
这是正确的(同样的修复适用于checked:true):
csp: true
从清单中删除此行:
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
继续搜索:)
答案 1 :(得分:0)
这是聚合物飞镖的基本例子
https://github.com/dart-gde/dart-chrome-app-samples/tree/master/chrome-app-with-polymer-dart
编辑:您需要在pubspec.yaml中拥有这些
transformers:
- polymer:
entry_points: web/index.html
csp: true
- chrome
- $dart2js:
csp: true
并从manifest.json中删除content_security_policy
这应该有效