我有一個onMessage.addListener功能是這樣的:每次使用onMessage.addListener responseCallback時,是否必須調用return true?
chrome.runtime.onMessage.addListener(function (r, s, sendResponse) {
if (r.action == "read") {
readManga(request, function() {
sendResponse({});
}, true);
}
if (r.action == "write") {
readManga(request, function() {
sendResponse({});
}, true);
}
if (request.action == "update") {
$.each(request.list, function (index, val) {
resetManga(val, function() {}, false);
});
saveList();
refreshUpdate();
sendResponse({});
}
if (request.action == "release") {
releaseImplentationFromId(request.id, function (mirrorName) {
updateMirrors(function() {
sendResponse({
mirror : mirrorName
});
});
return true
});
}
}
(這是摘錄,但it's working code並請忽略所有的,如果的,因爲很久以前我應該使用情況)
每次我使用回調函數sendResponse
(同樣,我需要重命名它,但讓我們忽略它)如定義in the documentation從不使用,除非我的return true
執行後。這真的很有必要,或者我剛剛發現一個骯髒的黑客,我做錯了什麼?
[Chrome擴展消息傳遞:響應未發送]的可能重複(https://stackoverflow.com/questions/20077487/chrome-extension-message-passing-response-not-sent) – Makyen