You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
50 lines
1.4 KiB
// 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();
|
|
|