Skip to content

Commit 207a30c

Browse files
committed
Fix no-op check to work with Safari and support of old browsers.
Verify the object that might be at `globalThis.browser` is not already implementing the basic Web Extension APIs. This is symmetric with the check to verify the poly fill is only included in extension contexts. Don't use optional-chaining for these checks, since this needs to continuing working in older browsers.
1 parent 0cf8915 commit 207a30c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/browser-polyfill.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
77
"use strict";
88

9-
if (!globalThis.chrome?.runtime?.id) {
9+
if (!(globalThis.chrome && globalThis.chrome.runtime && globalThis.chrome.runtime.id)) {
1010
throw new Error("This script should only be loaded in a browser extension.");
1111
}
1212

13-
if (typeof globalThis.browser === "undefined" || Object.getPrototypeOf(globalThis.browser) !== Object.prototype) {
13+
if (!(globalThis.browser && globalThis.browser.runtime && globalThis.browser.runtime.id)) {
1414
const CHROME_SEND_MESSAGE_CALLBACK_NO_RESPONSE_MESSAGE = "The message port closed before a response was received.";
1515

1616
// Wrapping the bulk of this polyfill in a one-time-use function is a minor

0 commit comments

Comments
 (0)