1

我在 Firefox 插件开发中遇到了一件奇怪的事情:我编写这样的代码(我将注释代码从 Chrome 扩展转换为 Firefox 插件代码):

function sendStoreIdentitiesMessage(identities, remember){
    console.log("Storing identities: "+identities.length);
    if(remember==null){
        remember=false;
    }
    //extension.sendMessage({type:"save.identities", identities:identities, remember:remember}, function(response) {
    //  identitiesNum=identities.length;
    //  identitiesDate=new Date();
    //  sendGetPageIdsMessage(function(){showCodeImageSuccess();});
    //});
    
    self.postMessage({type:"save.identities", identities:identities, remember:remember});
    self.port.on("response.save.identities",function(response){
        identitiesNum=identities.length;
        identitiesDate=new Date();
        sendGetPageIdsMessage(function(){showCodeImageSuccess();});
    });
}

当我用 Addon Builder 编译它时,它得到了错误:

“错误:NS_ERROR_XPC_NOT_ENOUGH_ARGS:没有足够的参数 [nsIDOMWindow.postMessage]”

然后我像这样更改代码:

function sendStoreIdentitiesMessage(identities, remember){
    console.log("Storing identities: "+identities.length);
    if(remember==null){
        remember=false;
    }
    //extension.sendMessage({type:"save.identities", identities:identities, remember:remember}, function(response) {
    //  identitiesNum=identities.length;
    //  identitiesDate=new Date();
    //  sendGetPageIdsMessage(function(){showCodeImageSuccess();});
    //});
    
    self.port.emit("message",{type:"save.identities", identities:identities, remember:remember});
    self.port.on("response.save.identities",function(response){
        identitiesNum=identities.length;
        identitiesDate=new Date();
        sendGetPageIdsMessage(function(){showCodeImageSuccess();});
    });
}

我得到另一个错误:

类型错误:self.port 未定义。

那么,怎么了?

4

1 回答 1

2

更改selfaddon.Detailed 文档在这里

于 2013-07-31T07:11:55.967 回答