[Solved] Do I have to call return true each time I use onMessage.addListener responseCallback?


This is the expected behavior and clearly stated in the documentation:

This function [sendResponse] becomes invalid when the event listener returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this will keep the message channel open to the other end until sendResponse is 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”.

2

solved Do I have to call return true each time I use onMessage.addListener responseCallback?