类似的问题已经存在了一段时间,也许有人知道今天堆栈的答案。理想情况下保留可调试性...
我有一个 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" ] }
]
}
背景.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';
}
点击计数器元素是来自 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% 作为网络应用程序运行):
Breaking on exception: Unsupported operation: Unsupported uri scheme chrome-extension for library LibraryMirror on 'my_clock'.
最佳答案
这甚至不是部分答案,但可能对其他人有帮助......
csp 行有一个常见的拼写错误。不要写:
csp: 'true'
这是正确的(相同的修复适用于检查:true):
csp: true
并从 list 中删除此行:
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
搜索继续:)
关于dart - Polymer、Dart、Chrome 应用程序、CSP 和调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31528895/