diff --git a/addon/webextension/assertIsTrusted.js b/addon/webextension/assertIsTrusted.js index ea606097c6..d80e83ac80 100644 --- a/addon/webextension/assertIsTrusted.js +++ b/addon/webextension/assertIsTrusted.js @@ -2,7 +2,7 @@ https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted Should be applied *inside* catcher.watchFunction */ -function assertIsTrusted(handlerFunction) { +this.assertIsTrusted = function assertIsTrusted(handlerFunction) { return function (event) { if (! event) { let exc = new Error("assertIsTrusted did not get an event"); @@ -17,3 +17,4 @@ function assertIsTrusted(handlerFunction) { return handlerFunction.call(this, event); }; } +null; diff --git a/addon/webextension/background/analytics.js b/addon/webextension/background/analytics.js index 81d805263c..ed41bca2bb 100644 --- a/addon/webextension/background/analytics.js +++ b/addon/webextension/background/analytics.js @@ -2,7 +2,7 @@ "use strict"; -window.analytics = (function () { +this.analytics = (function () { let exports = {}; let telemetryPrefKnown = false; diff --git a/addon/webextension/background/auth.js b/addon/webextension/background/auth.js index a14f2cdce3..05ccfb588d 100644 --- a/addon/webextension/background/auth.js +++ b/addon/webextension/background/auth.js @@ -3,7 +3,7 @@ "use strict"; -window.auth = (function () { +this.auth = (function () { let exports = {}; let registrationInfo; diff --git a/addon/webextension/background/communication.js b/addon/webextension/background/communication.js index 2995d7a001..d837df8a81 100644 --- a/addon/webextension/background/communication.js +++ b/addon/webextension/background/communication.js @@ -2,7 +2,7 @@ "use strict"; -window.communication = (function () { +this.communication = (function () { let exports = {}; let registeredFunctions = {}; diff --git a/addon/webextension/background/deviceInfo.js b/addon/webextension/background/deviceInfo.js index 0137f5cb6e..9ab5bb00c2 100644 --- a/addon/webextension/background/deviceInfo.js +++ b/addon/webextension/background/deviceInfo.js @@ -2,7 +2,7 @@ "use strict"; -window.deviceInfo = (function () { +this.deviceInfo = (function () { let manifest = browser.runtime.getManifest(); let platformInfo = {}; diff --git a/addon/webextension/background/main.js b/addon/webextension/background/main.js index 560c9f7947..b7b0f3fec1 100644 --- a/addon/webextension/background/main.js +++ b/addon/webextension/background/main.js @@ -3,7 +3,7 @@ "use strict"; -window.main = (function () { +this.main = (function () { let exports = {}; const pasteSymbol = (window.navigator.platform.match(/Mac/i)) ? "\u2318" : "Ctrl"; diff --git a/addon/webextension/background/selectorLoader.js b/addon/webextension/background/selectorLoader.js index 6ced014b94..37e6f2cd23 100644 --- a/addon/webextension/background/selectorLoader.js +++ b/addon/webextension/background/selectorLoader.js @@ -2,7 +2,7 @@ "use strict"; -window.selectorLoader = (function () { +this.selectorLoader = (function () { const exports = {}; // These modules are loaded in order, first standardScripts, then optionally onboardingScripts, and then selectorScripts @@ -37,10 +37,10 @@ window.selectorLoader = (function () { exports.unloadIfLoaded = function (tabId) { return browser.tabs.executeScript(tabId, { - code: "window.selectorLoader && window.selectorLoader.unloadModules()", + code: "this.selectorLoader && this.selectorLoader.unloadModules()", runAt: "document_start" }).then(result => { - return result && result.toString() === "true"; + return result && result[0]; }); }; @@ -84,7 +84,7 @@ window.selectorLoader = (function () { filename.replace(/^.*\//, "").replace(/\.js$/, "")); moduleNames.reverse(); for (let moduleName of moduleNames) { - let moduleObj = window[moduleName]; + let moduleObj = global[moduleName]; if (moduleObj && moduleObj.unload) { try { watchFunction(moduleObj.unload)(); @@ -92,7 +92,7 @@ window.selectorLoader = (function () { // ignore (watchFunction handles it) } } - delete window[moduleName]; + delete global[moduleName]; } return true; }; diff --git a/addon/webextension/background/senderror.js b/addon/webextension/background/senderror.js index c9a8eda634..d096423dee 100644 --- a/addon/webextension/background/senderror.js +++ b/addon/webextension/background/senderror.js @@ -2,7 +2,7 @@ "use strict"; -window.senderror = (function () { +this.senderror = (function () { let exports = {}; // Do not show an error more than every ERROR_TIME_LIMIT milliseconds: diff --git a/addon/webextension/background/takeshot.js b/addon/webextension/background/takeshot.js index 38c99f2325..3d7c090282 100644 --- a/addon/webextension/background/takeshot.js +++ b/addon/webextension/background/takeshot.js @@ -2,7 +2,7 @@ "use strict"; -window.takeshot = (function () { +this.takeshot = (function () { let exports = {}; const Shot = shot.AbstractShot; const { sendEvent } = analytics; diff --git a/addon/webextension/catcher.js b/addon/webextension/catcher.js index d1a7248085..7810da313a 100644 --- a/addon/webextension/catcher.js +++ b/addon/webextension/catcher.js @@ -1,6 +1,8 @@ "use strict"; -window.catcher = (function () { +var global = this; + +this.catcher = (function () { let exports = {}; let handler; diff --git a/addon/webextension/clipboard.js b/addon/webextension/clipboard.js index c9dd84bd12..5eb799577f 100644 --- a/addon/webextension/clipboard.js +++ b/addon/webextension/clipboard.js @@ -2,7 +2,7 @@ "use strict"; -window.clipboard = (function () { +this.clipboard = (function () { let exports = {}; exports.copy = function (text) { diff --git a/addon/webextension/domainFromUrl.js b/addon/webextension/domainFromUrl.js index 6f8f4e6d05..4b68d6caf5 100644 --- a/addon/webextension/domainFromUrl.js +++ b/addon/webextension/domainFromUrl.js @@ -4,7 +4,7 @@ "use strict"; -window.domainFromUrl = (function () { +this.domainFromUrl = (function () { return function urlDomainForId(location) { // eslint-disable-line no-unused-vars let domain = location.hostname; diff --git a/addon/webextension/makeUuid.js b/addon/webextension/makeUuid.js index 12e6d98a23..17d43625d4 100644 --- a/addon/webextension/makeUuid.js +++ b/addon/webextension/makeUuid.js @@ -1,6 +1,6 @@ "use strict"; -window.makeUuid = (function () { +this.makeUuid = (function () { // generates a v4 UUID return function makeUuid() { // eslint-disable-line no-unused-vars diff --git a/addon/webextension/onboarding/slides.js b/addon/webextension/onboarding/slides.js index 45a5ca92a5..a191f59c46 100644 --- a/addon/webextension/onboarding/slides.js +++ b/addon/webextension/onboarding/slides.js @@ -2,7 +2,7 @@ "use strict"; -window.slides = (function () { +this.slides = (function () { let exports = {}; const { watchFunction } = catcher; diff --git a/addon/webextension/randomString.js b/addon/webextension/randomString.js index 072c2bdcef..3721927bad 100644 --- a/addon/webextension/randomString.js +++ b/addon/webextension/randomString.js @@ -2,7 +2,7 @@ "use strict"; -function randomString(length, chars) { +this.randomString = function randomString(length, chars) { let randomStringChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; chars = chars || randomStringChars; let result = ""; diff --git a/addon/webextension/selector/callBackground.js b/addon/webextension/selector/callBackground.js index b91996c58b..4f653fffc1 100644 --- a/addon/webextension/selector/callBackground.js +++ b/addon/webextension/selector/callBackground.js @@ -2,7 +2,7 @@ "use strict"; -function callBackground (funcName, ...args) { +this.callBackground = function callBackground (funcName, ...args) { return browser.runtime.sendMessage({funcName, args}).then((result) => { if (result.type === "success") { return result.value; diff --git a/addon/webextension/selector/documentMetadata.js b/addon/webextension/selector/documentMetadata.js index 23609e70f1..fc93b013c6 100644 --- a/addon/webextension/selector/documentMetadata.js +++ b/addon/webextension/selector/documentMetadata.js @@ -1,6 +1,6 @@ "use strict"; -window.documentMetadata = (function () { +this.documentMetadata = (function () { function findSiteName() { let el = document.querySelector("meta[property='og:site_name']"); diff --git a/addon/webextension/selector/shooter.js b/addon/webextension/selector/shooter.js index 511073d74a..1840a5cab5 100644 --- a/addon/webextension/selector/shooter.js +++ b/addon/webextension/selector/shooter.js @@ -4,7 +4,7 @@ "use strict"; -window.shooter = (function () { // eslint-disable-line no-unused-vars +this.shooter = (function () { // eslint-disable-line no-unused-vars let exports = {}; const { AbstractShot } = window.shot; diff --git a/addon/webextension/selector/ui.js b/addon/webextension/selector/ui.js index c3d9c6a038..4bc54b6bc0 100644 --- a/addon/webextension/selector/ui.js +++ b/addon/webextension/selector/ui.js @@ -3,7 +3,7 @@ "use strict"; -window.ui = (function () { // eslint-disable-line no-unused-vars +this.ui = (function () { // eslint-disable-line no-unused-vars let exports = {}; const SAVE_BUTTON_HEIGHT = 50; diff --git a/addon/webextension/selector/uicontrol.js b/addon/webextension/selector/uicontrol.js index 88aba680c6..462d803596 100644 --- a/addon/webextension/selector/uicontrol.js +++ b/addon/webextension/selector/uicontrol.js @@ -3,7 +3,7 @@ "use strict"; -window.uicontrol = (function () { +this.uicontrol = (function () { let exports = {}; /********************************************************** diff --git a/addon/webextension/selector/util.js b/addon/webextension/selector/util.js index a834526d54..19dc576a72 100644 --- a/addon/webextension/selector/util.js +++ b/addon/webextension/selector/util.js @@ -1,6 +1,6 @@ "use strict"; -window.util = (function () { // eslint-disable-line no-unused-vars +this.util = (function () { // eslint-disable-line no-unused-vars let exports = {}; /** Removes a node from its document, if it's a node and the node is attached to a parent */ diff --git a/addon/webextension/sitehelper.js b/addon/webextension/sitehelper.js index dfb0335df0..250a10352a 100644 --- a/addon/webextension/sitehelper.js +++ b/addon/webextension/sitehelper.js @@ -4,7 +4,7 @@ "use strict"; -window.sitehelper = (function () { +this.sitehelper = (function () { catcher.registerHandler((errorObj) => { callBackground("reportError", errorObj); @@ -40,3 +40,4 @@ window.sitehelper = (function () { sendCustomEvent("addon-present"); })(); +null;