-
Notifications
You must be signed in to change notification settings - Fork 233
Description
Related:
- Chrome: "The message port closed before a response was received." #130
webextension-polyfill/src/browser-polyfill.js
Lines 488 to 489 in f818ecb
if (extensionAPIs.runtime.lastError.message === CHROME_SEND_MESSAGE_CALLBACK_NO_RESPONSE_MESSAGE) { resolve();
From my understanding, the code above was added to silence the error Chrome throws when a message is received by the listener but not "handled" (i.e. the listener did not return a promise).
For Chrome, this is a user error: The user must call sendResponse, even without arguments.
Unfortunately the polyfill’s workaround means that I can't distinguish between:
- the tab never handled my request (if there's any listener registered)
- the tab closed before my request was answered
… because in both cases, the promise will resolve with undefined.
Since the solution to this problem is simple, I suggest surfacing this error instead of ignoring it. The solution for users is:
// use an async listener
browser.runtime.onMessage.addListener(async (message) => {
// Handled, done
});
// return anything (or better, a resolved promise)
browser.runtime.onMessage.addListener((message) => {
return Promise.resolve();
});I understand however that this would be a breaking change, but the current situation means I can't use this polyfill to send long-running messages (e.g. send message, wait for HTTP response(2))