Dear Chromium Extension Developers,
TL;DR: If your extension uses runtime.onMessageExternal for asynchronous responses, you must now explicitly return true; to prevent the “The message port closed before a response was received.” error in Chromium 145.0.7614.0 and later.
As part of recent messaging changes, we identified and fixed a bug in the onMessageExternal listener that was not behaving per API documentation. Although this was mentioned in the original thread, we want to ensure wider visibility.
The runtime.onMessageExternal listener previously kept the message channel open even without explicitly returning true, allowing asynchronous responses without error. After the fix, developers must* explicitly return true; from the listener to send an asynchronous response and prevent a “The message port closed before a response was received.” error.
// background.js
function onMessageExternalListener(message, sender, sendResponse) {
setTimeout(() => {
sendResponse('pong');
}, 100);
// Listener should `return true;` but actually didn't need to.
}
chrome.runtime.onMessage.addListener(onMessageExternalListener);
After the fix, return true; is required:
// background.js
function onMessageExternalListener(message, sender, sendResponse) {
setTimeout(() => {
sendResponse('pong');
}, 100);
return true;
}
chrome.runtime.onMessage.addListener(onMessageExternalListener);
We apologize for any unexpected errors or inconvenience this may have caused. In the future, we will ensure API changes like this are announced more explicitly to give extension developers ample time to adapt.
Thank you,
Justin, on behalf of the Chromium Extensions Team