问题描述
我的问题很简单,我试图创建一个叫做NaCl模块的chrome扩展。我的按钮和不同的文件似乎没问题,我在C ++中的简单代码返回PostMessage hello World。但是,当我尝试它时,它不起作用。我有没有在Chrome扩展中包含NaCl模块的具体事情?
以下是我的background.html:
pre class =lang-html prettyprint-override>
< 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>
这是我的background.js:
var NaclCorrectionModule = null; //全局应用程序对象。
function moduleDidLoad(){
NaclCorrectionModule = document.getElementById('nacl_correction');
// alert(NaclCorrectionModule);
if(NaclCorrectionModule == null){
alert('Out');
}
其他{
alert(NaclCorrectionModule);
}
NaclCorrectionModule.addEventListener('message',handleMessage,false);
}
函数handleMessage(message_event){
alert(message_event.data);
}
chrome.browserAction.onClicked.addListener(moduleDidLoad);
最后,我的Manifest.json:
{
name:Correction de Cordial sous Chrome,
version:1.0 ,
background_page:background.html,
description:集成电子邮件,
权限:[
tabs,http:// * / *
],
browser_action:{
default_icon:corriger_big.png,//Icônede l'extension
default_title:Correction de Cordial//标题affiche sur bouton
}
}
如果有人有任何想法,我会很感激。
发现我忘了一些东西。在我的background.js中,我没有发送任何消息给NaCl,所以它不能工作。
我只需要添加1行:
NaclCorrectionModule.postMessage('');
感谢您阅读我的问题,我希望这可以帮助别人!!
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" :
{
"name": "Correction de Cordial sous Chrome",
"version": "1.0",
"background_page" :"background.html",
"description": "Intégration d'une extension Cordial pour la correction sous Chrome",
"permissions": [
"tabs", "http://*/*"
],
"browser_action": {
"default_icon": "corriger_big.png", // Icône de l'extension
"default_title": "Correction de Cordial" // Titre affiche sur le bouton
}
}
If anybody has any ideas, I would be thankful.
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!!
这篇关于在Chrome扩展程序中添加NaCl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!