類似的問題已經存在了一段時間,也許有人知道今天的堆棧的答案。理想情況下保留可調試性......Polymer,Dart,Chrome App,CSP和調試
我有一個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';
}
的點擊計數器元件是從達特/聚合物頁的標準代碼。
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%爲網絡應用)的錯誤消息:
Breaking on exception: Unsupported operation: Unsupported uri scheme chrome-extension for library LibraryMirror on 'my_clock'.
我很確定這兩個csp行是正確的和必要的。 –