Do I Have To Call Return True Each Time I Use Onmessage.addlistener Responsecallback?
I have the a onMessage.addListener function like this: chrome.runtime.onMessage.addListener(function (r, s, sendResponse) { if (r.action == 'read') { readManga(request,
Solution 1:
This is the expected behavior and clearly stated in the documentation:
This function [
sendResponse] becomes invalid when the event listener returns, unless you returntruefrom the event listener to indicate you wish to send a response asynchronously (this will keep the message channel open to the other end untilsendResponseis called).
Your function updateMirrors is apparently asynchronous: the callback function does not get executed immediately but is sent into a queue. So, you're not returning true "after" its execution, you are actually hitting return true before sendResponse.
Therefore, it's necessary to tell Chrome "expect an answer later".

Post a Comment for "Do I Have To Call Return True Each Time I Use Onmessage.addlistener Responsecallback?"