From d13aabde2307af821b93ecb1b3221b07112e48b2 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Tue, 8 Dec 2020 15:08:31 -0330 Subject: [PATCH] Fix SES lockdown on older browsers (#10014) On older browsers that don't support `globalThis`[1], the SES lockdown throws an error. The `globalthis` shim has been added to all pages, to the background process, and to the `contentscript`. This should prevent the error on older browsers. [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis#Browser_compatibility --- app/home.html | 1 + app/manifest/_base.json | 8 +++++++- app/notification.html | 1 + app/phishing.html | 1 + app/popup.html | 1 + development/build/static.js | 4 ++++ package.json | 1 + 7 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/home.html b/app/home.html index 4979ccb3b..072eddea9 100644 --- a/app/home.html +++ b/app/home.html @@ -10,6 +10,7 @@
+ diff --git a/app/manifest/_base.json b/app/manifest/_base.json index e27c3285f..8b2e971dd 100644 --- a/app/manifest/_base.json +++ b/app/manifest/_base.json @@ -2,6 +2,7 @@ "author": "https://metamask.io", "background": { "scripts": [ + "globalthis.js", "initSentry.js", "lockdown.cjs", "runLockdown.js", @@ -36,7 +37,12 @@ "content_scripts": [ { "matches": ["file://*/*", "http://*/*", "https://*/*"], - "js": ["lockdown.cjs", "runLockdown.js", "contentscript.js"], + "js": [ + "globalthis.js", + "lockdown.cjs", + "runLockdown.js", + "contentscript.js" + ], "run_at": "document_start", "all_frames": true }, diff --git a/app/notification.html b/app/notification.html index b55a63142..4f424e3c0 100644 --- a/app/notification.html +++ b/app/notification.html @@ -33,6 +33,7 @@
+ diff --git a/app/phishing.html b/app/phishing.html index 1c913db2e..59ea3ac71 100644 --- a/app/phishing.html +++ b/app/phishing.html @@ -2,6 +2,7 @@ Ethereum Phishing Detection - MetaMask + diff --git a/app/popup.html b/app/popup.html index 4d29f6153..e73f3e4d2 100644 --- a/app/popup.html +++ b/app/popup.html @@ -10,6 +10,7 @@
+ diff --git a/development/build/static.js b/development/build/static.js index 142f290d1..1fe5dc959 100644 --- a/development/build/static.js +++ b/development/build/static.js @@ -44,6 +44,10 @@ const copyTargets = [ pattern: `*.html`, dest: ``, }, + { + src: `./node_modules/globalthis/dist/browser.js`, + dest: `globalthis.js`, + }, { src: `./node_modules/ses/dist/`, pattern: `lockdown.cjs`, diff --git a/package.json b/package.json index f11903fbb..7260707b6 100644 --- a/package.json +++ b/package.json @@ -128,6 +128,7 @@ "extensionizer": "^1.0.1", "fast-json-patch": "^2.0.4", "fuse.js": "^3.2.0", + "globalthis": "^1.0.1", "human-standard-token-abi": "^2.0.0", "json-rpc-engine": "^6.1.0", "json-rpc-middleware-stream": "^2.1.1",