Remove some polyfills

This should reduce the runtime size & load times somewhat by removing polyfills for older browsers which are not used much
This commit is contained in:
AaronDewes 2022-08-09 15:06:07 +00:00
parent 625fdf5bca
commit 64644b57e3
6 changed files with 27 additions and 163 deletions

View file

@ -45,13 +45,7 @@ async function checkCrypto() {
);
return true;
} catch (err) {
try {
window.asmCrypto = await import('asmcrypto.js');
await import('@dannycoates/webcrypto-liner/build/shim');
return true;
} catch (e) {
return false;
}
return false;
}
}
@ -66,25 +60,12 @@ function checkStreams() {
}
}
async function polyfillStreams() {
try {
await import('@mattiasbuelens/web-streams-polyfill');
return true;
} catch (e) {
return false;
}
}
export default async function getCapabilities() {
const browser = browserName();
const isMobile = /mobi|android/i.test(navigator.userAgent);
const serviceWorker = 'serviceWorker' in navigator && browser !== 'edge';
let crypto = await checkCrypto();
const nativeStreams = checkStreams();
let polyStreams = false;
if (!nativeStreams) {
polyStreams = await polyfillStreams();
}
let account = typeof AUTH_CONFIG !== 'undefined';
try {
account = account && !!localStorage;
@ -106,10 +87,10 @@ export default async function getCapabilities() {
account,
crypto,
serviceWorker,
streamUpload: nativeStreams || polyStreams,
streamUpload: nativeStreams,
streamDownload:
nativeStreams && serviceWorker && browser !== 'safari' && !mobileFirefox,
multifile: nativeStreams || polyStreams,
multifile: nativeStreams,
share,
standalone
};

View file

@ -48,7 +48,7 @@ class ECETransformer {
name: 'AES-GCM',
length: 128
},
true, // Edge polyfill requires key to be extractable to encrypt :/
false,
['encrypt', 'decrypt']
);
}

View file

@ -23,39 +23,34 @@ function locale() {
return document.querySelector('html').lang;
}
function loadShim(polyfill) {
return new Promise((resolve, reject) => {
const shim = document.createElement('script');
shim.src = polyfill;
shim.addEventListener('load', () => resolve(true));
shim.addEventListener('error', () => resolve(false));
document.head.appendChild(shim);
});
}
function isFile(id) {
return /^[0-9a-fA-F]{10,16}$/.test(id);
}
function copyToClipboard(str) {
const aux = document.createElement('input');
aux.setAttribute('value', str);
aux.contentEditable = true;
aux.readOnly = true;
document.body.appendChild(aux);
if (navigator.userAgent.match(/iphone|ipad|ipod/i)) {
const range = document.createRange();
range.selectNodeContents(aux);
const sel = getSelection();
sel.removeAllRanges();
sel.addRange(range);
aux.setSelectionRange(0, str.length);
} else {
aux.select();
async function copyToClipboard(str) {
try {
await navigator.clipboard.writeText(str);
} catch {
// Older browsers or the clipboard API fails because of a missing permission
const aux = document.createElement('input');
aux.setAttribute('value', str);
aux.contentEditable = true;
aux.readOnly = true;
document.body.appendChild(aux);
if (navigator.userAgent.match(/iphone|ipad|ipod/i)) {
const range = document.createRange();
range.selectNodeContents(aux);
const sel = getSelection();
sel.removeAllRanges();
sel.addRange(range);
aux.setSelectionRange(0, str.length);
} else {
aux.select();
}
const result = document.execCommand('copy');
document.body.removeChild(aux);
return result;
}
const result = document.execCommand('copy');
document.body.removeChild(aux);
return result;
}
const LOCALIZE_NUMBERS = !!(
@ -287,7 +282,6 @@ module.exports = {
copyToClipboard,
arrayToB64,
b64ToArray,
loadShim,
isFile,
openLinksInNewTab,
browserName,