Module Load Progress Events in NaCl with manifest_version = 2 and no inline javascript

做~自己de王妃 提交于 2019-12-24 15:23:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!