我的后台脚本中有以下代码。我向另一个应用程序发送一条消息,但如果它失败了,它会被调用两次(注意:我的回调被调用了两次。我的代码调用sendMessage
只被调用一次)!
chrome.runtime.sendMessage(
otherAppId,
someObject,
function (response)
{
var lastError = chrome.runtime.lastError;
//This likely means it doesn't exist ("Could not establish connection. Receiving end does not exist.")
if ( lastError && lastError.message.indexOf( "not exist" ) !== -1 )
{
///This gets called twice!
console.log( "we're here twice?!" );
}
//This is called once
else console.log( "Was successful, so called only once" );
}
);
有没有办法取消它,让它停止再次尝试?为什么错误会导致两次调用我的回调?