问题
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.
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?
回答1:
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);
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.
来源:https://stackoverflow.com/questions/11811681/module-load-progress-events-in-nacl-with-manifest-version-2-and-no-inline-java