Adding NaCl in an Chrome Extension

匿名 (未验证) 提交于 2019-12-03 02:50:02

问题:

My question is quite simple, I tried to create a chrome extension that calls a NaCl module. My button and different files seem to be ok, and my quite simple code in C++ returns a PostMessage hello World. But, when I try it, it doesn't work. Are there specific things that I haven't done for including a NaCl module in a Chrome extension? I must say that I'm a little bit losing hope.

Here is my "background.html":

<body>   <script src="background.js"></script>   <div id="listener">     <embed name="nacl_module"       id="nacl_correction"       src="nacl_correction.nmf"       type="application/x-nacl" />   </div>   <script >    document.getElementById('listener').addEventListener('load', moduleDidLoad, true);   </script> </body> 

Here is my "background.js" :

var NaclCorrectionModule = null;  // Global application object.  function moduleDidLoad() {     NaclCorrectionModule = document.getElementById('nacl_correction');     //alert( NaclCorrectionModule);     if (NaclCorrectionModule == null) {         alert('Out');         }     else {         alert (NaclCorrectionModule);            }     NaclCorrectionModule.addEventListener('message', handleMessage, false); }  function handleMessage(message_event) {    alert(message_event.data); } chrome.browserAction.onClicked.addListener(moduleDidLoad); 

And, at last, my "Manifest.json" :

If anybody has any ideas, I would be thankful.

回答1:

After a little seeking, I've found that I forgot something. In my background.js, I didn't send any message to NaCl, so it can't work.

I only needed to add 1 line:

NaclCorrectionModule.postMessage(''); 

Thank you for reading my question, and I hope this can help somebody!!



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