Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle new "tab closed" response from Chrome #385

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/browser-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ if (typeof globalThis != "object" || typeof chrome != "object" || !chrome || !ch
}

if (typeof globalThis.browser === "undefined" || Object.getPrototypeOf(globalThis.browser) !== Object.prototype) {
const CHROME_SEND_MESSAGE_CALLBACK_NO_RESPONSE_MESSAGE = "The message port closed before a response was received.";
const CHROME_SEND_MESSAGE_CALLBACK_NO_LISTENER_MESSAGE = "The message port closed before a response was received.";
const CHROME_SEND_MESSAGE_CALLBACK_NO_RESPONSE_MESSAGE = "A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received"; // No period
const SEND_RESPONSE_DEPRECATION_WARNING = "Returning a Promise is the preferred way to send a reply from an onMessage/onMessageExternal listener, as the sendResponse will be removed from the specs (See https://developer.mozilla.org/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onMessage)";

// Wrapping the bulk of this polyfill in a one-time-use function is a minor
Expand Down Expand Up @@ -485,7 +486,11 @@ if (typeof globalThis.browser === "undefined" || Object.getPrototypeOf(globalThi
// Detect when none of the listeners replied to the sendMessage call and resolve
// the promise to undefined as in Firefox.
// See https://github.com/mozilla/webextension-polyfill/issues/130
if (extensionAPIs.runtime.lastError.message === CHROME_SEND_MESSAGE_CALLBACK_NO_RESPONSE_MESSAGE) {
// See https://github.com/mozilla/webextension-polyfill/issues/384
if (
extensionAPIs.runtime.lastError.message === CHROME_SEND_MESSAGE_CALLBACK_NO_RESPONSE_MESSAGE ||
extensionAPIs.runtime.lastError.message === CHROME_SEND_MESSAGE_CALLBACK_NO_LISTENER_MESSAGE
) {
resolve();
} else {
reject(new Error(extensionAPIs.runtime.lastError.message));
Expand Down