Browse Source

guard against an implicit global variable for <html id="browser"> (#613)

tophf 6 years ago
parent
commit
cf8691d6fc
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/common/browser.js

+ 7 - 1
src/common/browser.js

@@ -123,7 +123,13 @@ const meta = {
   },
   webRequest: true,
 };
-if (typeof browser === 'undefined' && typeof chrome !== 'undefined') {
+
+// Since this also runs in a content script we'll guard against implicit global variables
+// for DOM elements with 'id' attribute which is a standard feature, more info:
+// https://github.com/mozilla/webextension-polyfill/pull/153
+// https://html.spec.whatwg.org/multipage/window-object.html#named-access-on-the-window-object
+if ((typeof browser === 'undefined' || Object.getPrototypeOf(browser) !== Object.prototype)
+    && typeof chrome !== 'undefined') {
   global.browser = wrapAPIs(chrome, meta);
   // global.browser.__patched = true;
 }