NaCl中的manifest_version = 2且没有内联javascript的模块加载进度事件 [英] Module Load Progress Events in NaCl with manifest_version = 2 and no inline javascript
问题描述
我已根据此文档将我的manifest_version升级为"2",并且然后很惊讶地看到chrome处理了诸如此类的错误:
I upgraded my manifest_version to "2" as per this document, and then was suprised to see chrome burping up errors like:
拒绝执行内联脚本,因为它违反了以下内容安全策略指令
Refused to execute inline script because it violates the following Content Security Policy directive
虽然很清楚他们为什么会这样做,但是现在我不清楚我应该如何管理模块负载
While it is clear why they would do this, I am now unclear how i should be managing Module load progress events. Even if i ratchet it to the latest (dev) pepper release, the documentation is still recommending an inline script (which obviously doesn't work).
我有点沮丧(在花了一个周末的下午编写了进度条的模块负载之后),看到这个版本翻转并使我的东西完全无效.
I am a bit frustrated (after spending a weekend afternoon coding up a module load with progress) to see this version flip and render my stuff completely invalid.
所以,是的……这是为了更大的利益.我明白.但是现在我必须有一个独立的javascript文件(带有其自己的加载范例)并及时连接到<embed/>
元素才能正确捕获事件?现在执行此操作的新方法和改进方法是什么?
So, yeah...it is for the greater good. I understand. But now i have to have a standalone javascript file (with its own load paradigm) and hook up to the <embed/>
element in time to catch events correctly? What is the new and improved method for doing this now?
有人可以提出一种可靠的替代方案吗?
Can anyone suggest a reliable alternative to this sanctioned boilerplate?
推荐答案
According to the documentation for NaCl progress events, event listeners have to be added as follows:
<div id="listener">
<script type="text/javascript">
document.getElementById('listener').addEventListener('load', function() {
// Example
}, true);
</script>
<embed name="nacl_module" ... type="application/x-nacl" />
</div>
如果内容安全策略禁止,则此操作(另请参见).解决它的方法只有一种:通过将脚本移动到外部文件:
This if forbidden by the Content security policy (see also). There's only one way to solve it: By moving the script to an external file:
<div id="listener">
<script src="listener-load.js"></script>
<embed name="nacl_module" ... type="application/x-nacl" />
</div>
// listener-load.js:
document.getElementById('listener').addEventListener('load', ..., true);
由于在直到加载外部文件之前DOM块的构造,因此在插入<embed>
标记之前先加载脚本.由于外部文件与扩展名打包在一起,因此可以忽略对性能的影响.
Because the construction of the DOM blocks until the external file is loaded, the script is loaded before the <embed>
tag is inserted. Since the external files are packaged with the extension, the impact on performance can be neglected.
这篇关于NaCl中的manifest_version = 2且没有内联javascript的模块加载进度事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!