Skip to content

Commit

Permalink
fix: skip snow usage for MV3 test build (#19827)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
weizman and DDDDDanica authored Jun 30, 2023
1 parent 5545e5e commit a3f8119
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 8 additions & 0 deletions app/scripts/app-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
18 changes: 13 additions & 5 deletions app/scripts/use-snow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
});
})();

0 comments on commit a3f8119

Please sign in to comment.