增加兼容低版本内核的页面

This commit is contained in:
eafonyang
2026-06-02 19:55:09 +08:00
parent ccbafdd720
commit 28aa90296f
17 changed files with 1038 additions and 37 deletions
+47
View File
@@ -0,0 +1,47 @@
/**
* Minimal shims for Chrome 91 WebView (and similar legacy Chromium).
* Import once from main.legacy.tsx before the app mounts.
*/
if (typeof Object.hasOwn !== "function") {
Object.hasOwn = (obj, prop) =>
Object.prototype.hasOwnProperty.call(obj, prop);
}
if (!Array.prototype.at) {
// eslint-disable-next-line no-extend-native
Array.prototype.at = function at(index) {
const len = this.length;
const k = index >= 0 ? index : len + index;
if (k < 0 || k >= len) return undefined;
return this[k];
};
}
if (typeof globalThis.structuredClone !== "function") {
globalThis.structuredClone = (value) => JSON.parse(JSON.stringify(value));
}
/**
* Minimal shims for Chrome 91 WebView (and similar legacy Chromium).
* Import once from main.tsx before the app mounts.
*/
if (typeof Object.hasOwn !== "function") {
Object.hasOwn = (obj, prop) =>
Object.prototype.hasOwnProperty.call(obj, prop);
}
if (!Array.prototype.at) {
Array.prototype.at = function at(index) {
const len = this.length;
const k = index >= 0 ? index : len + index;
if (k < 0 || k >= len) return undefined;
return this[k];
};
}
if (typeof globalThis.structuredClone !== "function") {
globalThis.structuredClone = <T>(value: T): T =>
JSON.parse(JSON.stringify(value)) as T;
}
+9
View File
@@ -28,6 +28,15 @@ export function decodeCustomBase64(encoded: string): string {
const index = ALPHABET_CUSTOM.indexOf(char);
translated += index !== -1 ? ALPHABET_STANDARD.charAt(index) : char;
}
// Strip whitespace / newlines that may be present in API responses.
// Chrome 91 atob() is stricter than modern browsers and rejects these.
translated = translated.replace(/\s/g, "");
// Ensure correct Base64 padding (=). Modern atob() tolerates missing padding,
// but Chrome 91 throws "The string to be decoded is not correctly encoded".
const padNeeded = (4 - (translated.length % 4)) % 4;
if (padNeeded > 0) {
translated += "=".repeat(padNeeded);
}
const decoded = atob(translated);
const bytes = new Uint8Array(decoded.length);
for (let i = 0; i < decoded.length; i++) {