From a3f811957eb20224c22e6891db2427cff7c986d9 Mon Sep 17 00:00:00 2001 From: weizman Date: Fri, 30 Jun 2023 15:22:07 +0300 Subject: [PATCH] fix: skip snow usage for MV3 test build (#19827) * try fix * fix lint for app-init.js * fix lint for use-snow.js * remove comment in app-init.js --------- Co-authored-by: Danica Shen --- app/scripts/app-init.js | 8 ++++++++ app/scripts/use-snow.js | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/scripts/app-init.js b/app/scripts/app-init.js index 450c59597..f4cc97b83 100644 --- a/app/scripts/app-init.js +++ b/app/scripts/app-init.js @@ -60,6 +60,14 @@ function importAllScripts() { loadFile('./globalthis.js'); loadFile('./sentry-install.js'); + // eslint-disable-next-line no-undef + const isWorker = !self.document; + if (!isWorker) { + loadFile('./snow.js'); + } + + loadFile('./use-snow.js'); + // Always apply LavaMoat in e2e test builds, so that we can capture initialization stats if (testMode || applyLavaMoat) { loadFile('./runtime-lavamoat.js'); diff --git a/app/scripts/use-snow.js b/app/scripts/use-snow.js index 868db4e36..87d00be3d 100644 --- a/app/scripts/use-snow.js +++ b/app/scripts/use-snow.js @@ -8,14 +8,22 @@ Changing this code must be done cautiously to avoid breaking the app! // eslint-disable-next-line import/unambiguous (function () { const log = console.log.bind(console); + // eslint-disable-next-line no-undef + const isWorker = !self.document; const msg = 'Snow detected a new realm creation attempt in MetaMask. Performing scuttling on new realm.'; - Object.defineProperty(window.top, 'SCUTTLER', { + // eslint-disable-next-line no-undef + Object.defineProperty(self, 'SCUTTLER', { value: (realm, scuttle) => { - window.top.SNOW((win) => { - log(msg, win); - scuttle(win); - }, realm); + if (isWorker) { + scuttle(realm); + } else { + // eslint-disable-next-line no-undef + self.SNOW((win) => { + log(msg, win); + scuttle(win); + }, realm); + } }, }); })();