1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 20:39:08 +01:00
metamask-extension/app/scripts/app-init.js

51 lines
1.4 KiB
JavaScript

// eslint-disable-next-line import/unambiguous
function tryImport(...fileNames) {
try {
// eslint-disable-next-line
importScripts(...fileNames);
return true;
} catch (e) {
console.error(e);
return false;
}
}
function importAllScripts() {
const startImportScriptsTime = Date.now();
// applyLavaMoat has been hard coded to "true" as
// tryImport('./runtime-cjs.js') is giving issue with XMLHttpRequest object which is not avaialble to service worker.
// we need to dynamically inject values of applyLavaMoat once this is fixed.
const applyLavaMoat = true;
tryImport('./globalthis.js');
tryImport('./sentry-install.js');
if (applyLavaMoat) {
tryImport('./runtime-lavamoat.js');
tryImport('./lockdown-more.js');
tryImport('./policy-load.js');
} else {
tryImport('./lockdown-install.js');
tryImport('./lockdown-more.js');
tryImport('./lockdown-run.js');
tryImport('./runtime-cjs.js');
}
const fileList = [
// The list of files is injected at build time by replacing comment below with comma separated strings of file names
/** FILE NAMES */
];
fileList.forEach((fileName) => tryImport(fileName));
// for performance metrics/reference
console.log(
`SCRIPTS IMPORT COMPLETE in Seconds: ${
(Date.now() - startImportScriptsTime) / 1000
}`,
);
}
// Placing script import call here ensures that scripts are inported each time service worker is activated.
importAllScripts();