Revert "Remove some polyfills"

This reverts commit 64644b57e3.
This commit is contained in:
timvisee 2022-09-04 12:26:12 +02:00
parent 073accfe65
commit 4ceac20623
No known key found for this signature in database
GPG Key ID: B8DB720BC383E172
6 changed files with 163 additions and 27 deletions

View File

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

View File

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

View File

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

View File

@ -6,6 +6,8 @@
- https://github.com/whatwg/streams/tree/master/reference-implementation - https://github.com/whatwg/streams/tree/master/reference-implementation
- Examples - Examples
- https://github.com/mdn/dom-examples/tree/master/streams - https://github.com/mdn/dom-examples/tree/master/streams
- Polyfill
- https://github.com/MattiasBuelens/web-streams-polyfill
# Encrypted Content Encoding # Encrypted Content Encoding

107
package-lock.json generated
View File

@ -36,7 +36,9 @@
"@babel/plugin-proposal-class-properties": "^7.16.7", "@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-syntax-dynamic-import": "^7.2.0", "@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.16.11", "@babel/preset-env": "^7.16.11",
"@dannycoates/webcrypto-liner": "^0.1.37",
"@fullhuman/postcss-purgecss": "^4.1.3", "@fullhuman/postcss-purgecss": "^4.1.3",
"@mattiasbuelens/web-streams-polyfill": "0.2.1",
"@sentry/browser": "^5.30.0", "@sentry/browser": "^5.30.0",
"asmcrypto.js": "^0.22.0", "asmcrypto.js": "^0.22.0",
"babel-loader": "^8.2.4", "babel-loader": "^8.2.4",
@ -1906,6 +1908,21 @@
"postcss-selector-parser": "^6.0.10" "postcss-selector-parser": "^6.0.10"
} }
}, },
"node_modules/@dannycoates/elliptic": {
"version": "6.4.2",
"resolved": "https://registry.npmjs.org/@dannycoates/elliptic/-/elliptic-6.4.2.tgz",
"integrity": "sha512-2G4qWMB2SRBk4H75d+BFBbz2b1cseIYCI8G7duGxtxdnjGxhewpripDsVr1lCagmijyYX4zDyfKTNoId5GGyow==",
"dev": true,
"dependencies": {
"bn.js": "^4.4.0",
"brorand": "^1.0.1",
"hash.js": "^1.0.0",
"hmac-drbg": "^1.0.0",
"inherits": "^2.0.1",
"minimalistic-assert": "^1.0.0",
"minimalistic-crypto-utils": "^1.0.0"
}
},
"node_modules/@dannycoates/express-ws": { "node_modules/@dannycoates/express-ws": {
"version": "5.0.3", "version": "5.0.3",
"resolved": "https://registry.npmjs.org/@dannycoates/express-ws/-/express-ws-5.0.3.tgz", "resolved": "https://registry.npmjs.org/@dannycoates/express-ws/-/express-ws-5.0.3.tgz",
@ -1921,6 +1938,17 @@
"express": "^4.0.0 || ^5.0.0-alpha.1" "express": "^4.0.0 || ^5.0.0-alpha.1"
} }
}, },
"node_modules/@dannycoates/webcrypto-liner": {
"version": "0.1.37",
"resolved": "https://registry.npmjs.org/@dannycoates/webcrypto-liner/-/webcrypto-liner-0.1.37.tgz",
"integrity": "sha512-EM29TDkn7GJaa/oOfLeS1vrAxEkyM+WfUsmHTz7OyrxvMZNqz2SiYdZkXBIvg+QCnKTfXc2x//ORAilesugQlg==",
"dev": true,
"dependencies": {
"@dannycoates/elliptic": "^6.4.2",
"asmcrypto.js": "^0.22.0",
"webcrypto-core": "github:dannycoates/webcrypto-core"
}
},
"node_modules/@fluent/bundle": { "node_modules/@fluent/bundle": {
"version": "0.17.1", "version": "0.17.1",
"resolved": "https://registry.npmjs.org/@fluent/bundle/-/bundle-0.17.1.tgz", "resolved": "https://registry.npmjs.org/@fluent/bundle/-/bundle-0.17.1.tgz",
@ -2048,6 +2076,19 @@
"@jridgewell/sourcemap-codec": "^1.4.10" "@jridgewell/sourcemap-codec": "^1.4.10"
} }
}, },
"node_modules/@mattiasbuelens/web-streams-polyfill": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/@mattiasbuelens/web-streams-polyfill/-/web-streams-polyfill-0.2.1.tgz",
"integrity": "sha512-oKuFCQFa3W7Hj7zKn0+4ypI8JFm4ZKIoncwAC6wd5WwFW2sL7O1hpPoJdSWpynQ4DJ4lQ6MvFoVDmCLilonDFg==",
"deprecated": "moved to web-streams-polyfill@2.0.0",
"dev": true,
"dependencies": {
"@types/whatwg-streams": "^0.0.7"
},
"engines": {
"node": ">= 8"
}
},
"node_modules/@nodelib/fs.scandir": { "node_modules/@nodelib/fs.scandir": {
"version": "2.1.5", "version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@ -2480,6 +2521,12 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"node_modules/@types/whatwg-streams": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/@types/whatwg-streams/-/whatwg-streams-0.0.7.tgz",
"integrity": "sha512-6sDiSEP6DWcY2ZolsJ2s39ZmsoGQ7KVwBDI3sESQsEm9P2dHTcqnDIHRZFRNtLCzWp7hCFGqYbw5GyfpQnJ01A==",
"dev": true
},
"node_modules/@webassemblyjs/ast": { "node_modules/@webassemblyjs/ast": {
"version": "1.8.5", "version": "1.8.5",
"resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.8.5.tgz", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.8.5.tgz",
@ -21002,6 +21049,16 @@
"minimalistic-assert": "^1.0.0" "minimalistic-assert": "^1.0.0"
} }
}, },
"node_modules/webcrypto-core": {
"version": "0.1.19",
"resolved": "git+ssh://git@github.com/dannycoates/webcrypto-core.git#8e0152a66d3ae6329cf080ccb3085eb06637070f",
"integrity": "sha512-FQXkmbl8syEGw0LtxcbO5aBmC6dmntkMMSzUxnC0U3Ue8vRrS9LKFsNOfs2XK1Nr5Sw1uGA0k4n7RZXa44vHeQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"tslib": "^1.7.1"
}
},
"node_modules/webidl-conversions": { "node_modules/webidl-conversions": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
@ -23562,6 +23619,21 @@
"dev": true, "dev": true,
"requires": {} "requires": {}
}, },
"@dannycoates/elliptic": {
"version": "6.4.2",
"resolved": "https://registry.npmjs.org/@dannycoates/elliptic/-/elliptic-6.4.2.tgz",
"integrity": "sha512-2G4qWMB2SRBk4H75d+BFBbz2b1cseIYCI8G7duGxtxdnjGxhewpripDsVr1lCagmijyYX4zDyfKTNoId5GGyow==",
"dev": true,
"requires": {
"bn.js": "^4.4.0",
"brorand": "^1.0.1",
"hash.js": "^1.0.0",
"hmac-drbg": "^1.0.0",
"inherits": "^2.0.1",
"minimalistic-assert": "^1.0.0",
"minimalistic-crypto-utils": "^1.0.0"
}
},
"@dannycoates/express-ws": { "@dannycoates/express-ws": {
"version": "5.0.3", "version": "5.0.3",
"resolved": "https://registry.npmjs.org/@dannycoates/express-ws/-/express-ws-5.0.3.tgz", "resolved": "https://registry.npmjs.org/@dannycoates/express-ws/-/express-ws-5.0.3.tgz",
@ -23571,6 +23643,17 @@
"ws": "^7.1.1" "ws": "^7.1.1"
} }
}, },
"@dannycoates/webcrypto-liner": {
"version": "0.1.37",
"resolved": "https://registry.npmjs.org/@dannycoates/webcrypto-liner/-/webcrypto-liner-0.1.37.tgz",
"integrity": "sha512-EM29TDkn7GJaa/oOfLeS1vrAxEkyM+WfUsmHTz7OyrxvMZNqz2SiYdZkXBIvg+QCnKTfXc2x//ORAilesugQlg==",
"dev": true,
"requires": {
"@dannycoates/elliptic": "^6.4.2",
"asmcrypto.js": "^0.22.0",
"webcrypto-core": "github:dannycoates/webcrypto-core"
}
},
"@fluent/bundle": { "@fluent/bundle": {
"version": "0.17.1", "version": "0.17.1",
"resolved": "https://registry.npmjs.org/@fluent/bundle/-/bundle-0.17.1.tgz", "resolved": "https://registry.npmjs.org/@fluent/bundle/-/bundle-0.17.1.tgz",
@ -23671,6 +23754,15 @@
"@jridgewell/sourcemap-codec": "^1.4.10" "@jridgewell/sourcemap-codec": "^1.4.10"
} }
}, },
"@mattiasbuelens/web-streams-polyfill": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/@mattiasbuelens/web-streams-polyfill/-/web-streams-polyfill-0.2.1.tgz",
"integrity": "sha512-oKuFCQFa3W7Hj7zKn0+4ypI8JFm4ZKIoncwAC6wd5WwFW2sL7O1hpPoJdSWpynQ4DJ4lQ6MvFoVDmCLilonDFg==",
"dev": true,
"requires": {
"@types/whatwg-streams": "^0.0.7"
}
},
"@nodelib/fs.scandir": { "@nodelib/fs.scandir": {
"version": "2.1.5", "version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@ -24023,6 +24115,12 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"@types/whatwg-streams": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/@types/whatwg-streams/-/whatwg-streams-0.0.7.tgz",
"integrity": "sha512-6sDiSEP6DWcY2ZolsJ2s39ZmsoGQ7KVwBDI3sESQsEm9P2dHTcqnDIHRZFRNtLCzWp7hCFGqYbw5GyfpQnJ01A==",
"dev": true
},
"@webassemblyjs/ast": { "@webassemblyjs/ast": {
"version": "1.8.5", "version": "1.8.5",
"resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.8.5.tgz", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.8.5.tgz",
@ -38782,6 +38880,15 @@
"minimalistic-assert": "^1.0.0" "minimalistic-assert": "^1.0.0"
} }
}, },
"webcrypto-core": {
"version": "git+ssh://git@github.com/dannycoates/webcrypto-core.git#8e0152a66d3ae6329cf080ccb3085eb06637070f",
"integrity": "sha512-FQXkmbl8syEGw0LtxcbO5aBmC6dmntkMMSzUxnC0U3Ue8vRrS9LKFsNOfs2XK1Nr5Sw1uGA0k4n7RZXa44vHeQ==",
"dev": true,
"from": "webcrypto-core@github:dannycoates/webcrypto-core",
"requires": {
"tslib": "^1.7.1"
}
},
"webidl-conversions": { "webidl-conversions": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",

View File

@ -66,7 +66,9 @@
"@babel/plugin-proposal-class-properties": "^7.16.7", "@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-syntax-dynamic-import": "^7.2.0", "@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.16.11", "@babel/preset-env": "^7.16.11",
"@dannycoates/webcrypto-liner": "^0.1.37",
"@fullhuman/postcss-purgecss": "^4.1.3", "@fullhuman/postcss-purgecss": "^4.1.3",
"@mattiasbuelens/web-streams-polyfill": "0.2.1",
"@sentry/browser": "^5.30.0", "@sentry/browser": "^5.30.0",
"asmcrypto.js": "^0.22.0", "asmcrypto.js": "^0.22.0",
"babel-loader": "^8.2.4", "babel-loader": "^8.2.4",