Merge pull request #1276 from Rintim/Dev-Enhancement-FilterAbort
修复无效报错 && 替换game.js的逻辑
This commit is contained in:
commit
5a2842cd0f
|
@ -0,0 +1 @@
|
|||
// 空文件,只是用来加载
|
480
game/game.js
480
game/game.js
|
@ -1,41 +1,223 @@
|
|||
"use strict";
|
||||
|
||||
new Promise((resolve) => {
|
||||
// 客户端自带core.js的请注意跟进core.js版本
|
||||
if ("__core-js_shared__" in window) resolve(null);
|
||||
else {
|
||||
(async function () {
|
||||
// 预设定常量
|
||||
/**
|
||||
* 最低要求的Safari版本
|
||||
*
|
||||
* @type {[majorVersion: number, minorVersion: number, patchVersion: number]}
|
||||
*/
|
||||
const minSafariVersion = [14, 5, 0];
|
||||
|
||||
// 基础全局变量
|
||||
const nonameInitialized = localStorage.getItem("noname_inited");
|
||||
const assetURL =
|
||||
location.protocol.startsWith("http") ||
|
||||
typeof nonameInitialized != "string" ||
|
||||
nonameInitialized == "nodejs"
|
||||
? ""
|
||||
: nonameInitialized;
|
||||
const coreJSBundle = document.createElement("script");
|
||||
coreJSBundle.onerror = coreJSBundle.onload = resolve;
|
||||
coreJSBundle.src = `${assetURL}game/core-js-bundle.js`;
|
||||
document.head.appendChild(coreJSBundle);
|
||||
}
|
||||
}).then(() => {
|
||||
const nonameInitialized = localStorage.getItem("noname_inited");
|
||||
const assetURL =
|
||||
location.protocol.startsWith("http") ||
|
||||
typeof nonameInitialized != "string" ||
|
||||
nonameInitialized == "nodejs"
|
||||
? ""
|
||||
: nonameInitialized;
|
||||
const assetURL = location.protocol.startsWith("http") || typeof nonameInitialized != "string" || nonameInitialized == "nodejs" ? "" : nonameInitialized;
|
||||
const userAgent = navigator.userAgent.toLowerCase();
|
||||
|
||||
const exit = () => {
|
||||
const ios =
|
||||
userAgent.includes("iphone") ||
|
||||
userAgent.includes("ipad") ||
|
||||
userAgent.includes("macintosh");
|
||||
// 使用到的文本
|
||||
const globalText = {
|
||||
GPL_ALERT: ["①无名杀是一款基于GPLv3协议的开源软件!", "你可以在遵守GPLv3协议的基础上任意使用,修改并转发《无名杀》,以及所有基于《无名杀》开发的拓展。", "点击“确定”即代表您认可并接受GPLv3协议↓️", "https://www.gnu.org/licenses/gpl-3.0.html", "②无名杀官方发布地址仅有GitHub仓库!", "其他所有的所谓“无名杀”社群(包括但不限于绝大多数“官方”QQ群、QQ频道等)均为玩家自发组织,与无名杀官方无关!"].join("\n"),
|
||||
LOAD_ENTRY_FAILED: ["您使用的浏览器或《无名杀》客户端加载内容失败!", "请检查是否缺少游戏文件!隔版本更新请下载完整包而不是离线包!", "目前使用的浏览器UA信息为: ", userAgent, "若您使用的客户端为自带内核的旧版“兼容版”,请及时更新客户端版本!", "若您使用的客户端为手机端的非兼容版《无名杀》,请尝试更新手机的WebView内核,或者更换为1.8.2版本及以上的兼容版!", "若您是直接使用浏览器加载index.html进行游戏,请改为运行文件夹内的“noname-server.exe”(或使用VSCode等工具启动Live Server),以动态服务器的方式启动《无名杀》!", "若您使用的是苹果端,请至少将Safari升级至14.5.0!"].join("\n"),
|
||||
REDIRECT_TIP: ["您使用的浏览器或无名杀客户端内核版本过低,已经无法正常运行无名杀!", "目前使用的浏览器UA信息为: ", userAgent, "点击“确认”以前往GitHub下载最新版无名杀客户端(可能需要科学上网)。", "稍后您的无名杀将自动退出(可能的话)"].join("\n"),
|
||||
SAFARI_VERSION_NOT_SUPPORT: ["您使用的Safari浏览器无法支持当前无名杀所需的功能,请至少升级至14.5.0!", "当前浏览器的UA为: ", userAgent, "稍后您的无名杀将自动退出(可能的话)"].join("\n"),
|
||||
};
|
||||
|
||||
// 检查 window 对象中是否存在 "__core-js_shared__" 属性
|
||||
if (!("__core-js_shared__" in window)) {
|
||||
// 如果不存在,则执行以下操作
|
||||
await new Promise(resolve => {
|
||||
// 创建一个新的 <script> 元素
|
||||
const coreJSBundle = document.createElement("script");
|
||||
// 为 script 元素设置 onerror 和 onload 事件处理程序
|
||||
// 当出错或加载完成时,调用 resolve 函数以解决 Promise
|
||||
coreJSBundle.onerror = coreJSBundle.onload = resolve;
|
||||
// 设置 script 元素的 src 属性,指向 core-js-bundle.js 文件
|
||||
coreJSBundle.src = `${assetURL}game/core-js-bundle.js`;
|
||||
// 将 script 元素添加到 document.head 中
|
||||
document.head.appendChild(coreJSBundle);
|
||||
});
|
||||
}
|
||||
|
||||
// 检查是否已经显示过GPL许可协议警告
|
||||
if (!localStorage.getItem("gplv3_noname_alerted")) {
|
||||
// 判断游戏是否运行在HTTP环境中
|
||||
const gameInHttpEnvironment = location.protocol.startsWith("http");
|
||||
|
||||
// 判断游戏是否已经初始化过
|
||||
const gameIntialized = nonameInitialized && nonameInitialized.length > 0;
|
||||
|
||||
// 如果满足以下条件之一,则显示GPL许可协议警告:
|
||||
// 1. 游戏运行在HTTP环境中且已经初始化过
|
||||
// 2. 用户确认显示GPL许可协议警告
|
||||
if ((gameInHttpEnvironment && gameIntialized) || confirm(globalText.GPL_ALERT)) {
|
||||
// 记录已显示过GPL许可协议警告
|
||||
localStorage.setItem("gplv3_noname_alerted", String(true));
|
||||
} else {
|
||||
// 如果用户拒绝显示GPL许可协议警告,则退出程序
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
window["b" + "ann" + "e" + "dE" + "x" + "ten" + "s" + "i" + "o" + "ns"] = [
|
||||
"\u4fa0\u4e49",
|
||||
"\u5168\u6559\u7a0b",
|
||||
"在线更新", //游戏内在线更新方式修改了,不再依赖于在线更新扩展了
|
||||
];
|
||||
|
||||
// 检查是否是Safari浏览器
|
||||
// 通过检查用户代理字符串是否包含 "safari" 且不包含 "chrome",可以初步判断是不是Safari
|
||||
if (userAgent.includes("safari") && !userAgent.includes("chrome")) {
|
||||
// 如果是 Safari 浏览器,则进行以下操作
|
||||
// 获取 Safari 版本信息
|
||||
let [coreName, ...safariVersion] = getSafariVersion();
|
||||
// 检查 Safari 的内核名称是否为 "safari",以及版本号是否低于要求的最小版本号
|
||||
// 如果无法判定是Safari,则证明这个浏览器内核很玄乎,我们表示对未知的、不符合标准的内核无能为力,只能等出问题了再适配
|
||||
if (coreName === "safari" && !checkVersion(minSafariVersion, safariVersion)) {
|
||||
// 如果版本号低于要求的最小版本号,则执行以下操作
|
||||
// 显示警告消息
|
||||
alert(globalText.SAFARI_VERSION_NOT_SUPPORT);
|
||||
// 退出程序
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理Node环境下的http情况
|
||||
if (typeof window.require == "function" && typeof window.process == "object" && typeof window.__dirname == "string") {
|
||||
// 在http环境下修改__dirname和require的逻辑
|
||||
if (location.protocol.startsWith("http") && window.__dirname.endsWith("electron.asar\\renderer")) {
|
||||
const path = require("path");
|
||||
window.__dirname = path.join(path.resolve(), "resources/app");
|
||||
const oldData = Object.entries(window.require);
|
||||
// @ts-ignore
|
||||
window.require = function (moduleId) {
|
||||
try {
|
||||
return module.require(moduleId);
|
||||
} catch {
|
||||
return module.require(path.join(window.__dirname, moduleId));
|
||||
}
|
||||
};
|
||||
oldData.forEach(([key, value]) => {
|
||||
window.require[key] = value;
|
||||
});
|
||||
}
|
||||
// 增加导入ts的逻辑
|
||||
window.require.extensions[".ts"] = function (module, filename) {
|
||||
// @ts-ignore
|
||||
const _compile = module._compile;
|
||||
// @ts-ignore
|
||||
module._compile = function (code, fileName) {
|
||||
/**
|
||||
* @type { import("typescript") }
|
||||
*/
|
||||
// @ts-ignore
|
||||
const ts = require("./game/typescript.js");
|
||||
// 使用ts compiler对ts文件进行编译
|
||||
const result = ts.transpile(
|
||||
code,
|
||||
{
|
||||
module: ts.ModuleKind.CommonJS,
|
||||
//@todo: ES2019 -> ES2020
|
||||
target: ts.ScriptTarget.ES2019,
|
||||
inlineSourceMap: true,
|
||||
resolveJsonModule: true,
|
||||
esModuleInterop: true,
|
||||
},
|
||||
fileName
|
||||
);
|
||||
// 使用默认的js编译函数获取返回值
|
||||
return _compile.call(this, result, fileName);
|
||||
};
|
||||
// @ts-ignore
|
||||
module._compile(require("fs").readFileSync(filename, "utf8"), filename);
|
||||
};
|
||||
}
|
||||
|
||||
// 使serviceWorker加载完成后,再加载entry.js
|
||||
if (location.protocol.startsWith("http") && "serviceWorker" in navigator) {
|
||||
let scope = window.location.protocol + "//" + window.location.host + window.location.pathname;
|
||||
let registrations = await navigator.serviceWorker.getRegistrations();
|
||||
let findServiceWorker = registrations.find(registration => {
|
||||
return registration && registration.active && registration.active.scriptURL == `${scope}service-worker.js`;
|
||||
});
|
||||
|
||||
try {
|
||||
const registration_1 = await navigator.serviceWorker.register(`${scope}service-worker.js`, {
|
||||
type: "module",
|
||||
updateViaCache: "all",
|
||||
scope,
|
||||
});
|
||||
// 初次加载worker,需要重新启动一次
|
||||
if (!findServiceWorker) location.reload();
|
||||
// 接收消息,暂时没用到
|
||||
navigator.serviceWorker.addEventListener("message", e => {
|
||||
console.log(e);
|
||||
});
|
||||
registration_1.update().catch(e => console.error("worker update失败", e));
|
||||
if (!sessionStorage.getItem("canUseTs")) {
|
||||
await import("./canUse.ts")
|
||||
.then(({ text }) => console.log(text))
|
||||
.catch(() => {
|
||||
sessionStorage.setItem("canUseTs", "1");
|
||||
location.reload();
|
||||
});
|
||||
}
|
||||
} catch (e_1) {
|
||||
console.log("serviceWorker加载失败: ", e_1);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建一个新的 <script> 元素
|
||||
const script = document.createElement("script");
|
||||
// 设置该 <script> 元素为模块脚本
|
||||
script.type = "module";
|
||||
// 设置 <script> 元素的 src 属性,指向 entry.js 文件
|
||||
script.src = `${assetURL}game/entry.js`;
|
||||
// 设置该脚本为异步加载
|
||||
script.async = true;
|
||||
// 为 <script> 元素设置 onerror 事件处理程序
|
||||
script.onerror = event => {
|
||||
// 在控制台输出错误信息
|
||||
console.error(event);
|
||||
// 获取加载失败的提示信息
|
||||
const message = globalText.LOAD_ENTRY_FAILED;
|
||||
// 在控制台输出提示信息
|
||||
console.error(message);
|
||||
// 显示提示信息
|
||||
alert(message);
|
||||
// 退出程序
|
||||
exit();
|
||||
};
|
||||
// 将 <script> 元素添加到 document.head 中
|
||||
document.head.appendChild(script);
|
||||
|
||||
// 创建一个新的 <script> 元素,用于回退
|
||||
let fallback = document.createElement("script");
|
||||
// 设置该 <script> 元素为旧式脚本
|
||||
fallback.noModule = true;
|
||||
// 设置 <script> 元素的 src 属性,指向 fallback.js 文件
|
||||
fallback.src = `${assetURL}game/fallback.js`;
|
||||
// 为 <script> 元素设置 onload 事件处理程序
|
||||
fallback.onload = () => {
|
||||
// 显示一个确认对话框,询问是否要重定向到 GitHub 页面
|
||||
if (confirm(globalText.REDIRECT_TIP)) {
|
||||
// 如果确认,则打开新的浏览器窗口,跳转到指定的 GitHub 页面
|
||||
window.open("https://github.com/libccy/noname/releases/tag/chromium77-client");
|
||||
}
|
||||
// 退出程序
|
||||
exit();
|
||||
};
|
||||
// 将 <script> 元素添加到 document.head 中
|
||||
document.head.appendChild(fallback);
|
||||
|
||||
/**
|
||||
* 退出客户端用到的代码
|
||||
*
|
||||
* @author Spmario233
|
||||
*/
|
||||
function exit() {
|
||||
const ios = userAgent.includes("iphone") || userAgent.includes("ipad") || userAgent.includes("macintosh");
|
||||
//electron
|
||||
if (
|
||||
typeof window.process == "object" &&
|
||||
typeof window.require == "function"
|
||||
) {
|
||||
if (typeof window.process == "object" && typeof window.require == "function") {
|
||||
const versions = window.process.versions;
|
||||
// @ts-ignore
|
||||
const electronVersion = parseFloat(versions.electron);
|
||||
|
@ -57,70 +239,41 @@ new Promise((resolve) => {
|
|||
else if (!ios) {
|
||||
window.close();
|
||||
}
|
||||
};
|
||||
|
||||
// 这个弹窗,在升级到http协议下的客户端不应该进行提示。
|
||||
if (!localStorage.getItem("gplv3_noname_alerted")) {
|
||||
const nonameInitialized = localStorage.getItem("noname_inited");
|
||||
const callback = () => {
|
||||
if (
|
||||
confirm(
|
||||
"①无名杀是一款基于GPLv3协议的开源软件!\n你可以在遵守GPLv3协议的基础上任意使用,修改并转发《无名杀》,以及所有基于《无名杀》开发的拓展。\n点击“确定”即代表您认可并接受GPLv3协议↓️\nhttps://www.gnu.org/licenses/gpl-3.0.html\n②无名杀官方发布地址仅有GitHub仓库!\n其他所有的所谓“无名杀”社群(包括但不限于绝大多数“官方”QQ群、QQ频道等)均为玩家自发组织,与无名杀官方无关!"
|
||||
)
|
||||
) {
|
||||
// @ts-ignore
|
||||
localStorage.setItem("gplv3_noname_alerted", true);
|
||||
} else {
|
||||
exit();
|
||||
}
|
||||
};
|
||||
if (location.protocol.startsWith("http")) {
|
||||
if (!nonameInitialized || nonameInitialized.length == 0) {
|
||||
callback();
|
||||
} else {
|
||||
// @ts-ignore
|
||||
localStorage.setItem("gplv3_noname_alerted", true);
|
||||
}
|
||||
} else callback();
|
||||
}
|
||||
window["b" + "ann" + "e" + "dE" + "x" + "ten" + "s" + "i" + "o" + "ns"] = [
|
||||
"\u4fa0\u4e49",
|
||||
"\u5168\u6559\u7a0b",
|
||||
"在线更新", //游戏内在线更新方式修改了,不再依赖于在线更新扩展了
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取Safari的版本号
|
||||
*
|
||||
* @returns {["firefox" | "chrome" | "safari" | "other", number, number, number]}
|
||||
* @returns {[coreName: "safari" | "other", majorVersion: number, minorVersion: number, patchVersion: number]}
|
||||
*/
|
||||
function coreInfo() {
|
||||
const regex = /(firefox|chrome|safari)\/(\d+(?:\.\d+)+)/;
|
||||
function getSafariVersion() {
|
||||
let result;
|
||||
if (!(result = userAgent.match(regex))) return ["other", NaN, NaN, NaN];
|
||||
if (result[1] != "safari") {
|
||||
const [major, minor, patch] = result[2].split(".");
|
||||
// @ts-ignore
|
||||
return [
|
||||
result[1],
|
||||
parseInt(major),
|
||||
parseInt(minor),
|
||||
parseInt(patch),
|
||||
];
|
||||
}
|
||||
// 以下是所有Safari平台的判断方法
|
||||
// macOS以及以桌面显示的移动端则直接判断
|
||||
if (/macintosh/.test(userAgent)) {
|
||||
result = userAgent.match(/version\/(\d+(?:\.\d+)+).*safari/);
|
||||
if (!result) return ["other", NaN, NaN, NaN];
|
||||
}
|
||||
// 不然则通过OS后面的版本号来获取内容
|
||||
else {
|
||||
let safariRegex = /(?:iphone|ipad); cpu (?:iphone )?os (\d+(?:_\d+)+)/;
|
||||
result = userAgent.match(safariRegex);
|
||||
if (!result) return ["other", NaN, NaN, NaN];
|
||||
}
|
||||
// result = userAgent.match(/version\/(\d+(?:\.\d+)+).*safari/)
|
||||
// @ts-ignore
|
||||
const [major, minor, patch] = result[1].split(".");
|
||||
return ["safari", parseInt(major), parseInt(minor), parseInt(patch)];
|
||||
}
|
||||
const [core, major, minor, patch] = coreInfo();
|
||||
const supportMap = {
|
||||
firefox: [60, 0, 0],
|
||||
chrome: [61, 0, 0],
|
||||
safari: [14, 5, 0],
|
||||
};
|
||||
const versions = [major, minor, patch];
|
||||
|
||||
// require是需求的版本号,current是浏览器环境本身的版本号
|
||||
const check = (require, current) => {
|
||||
/**
|
||||
*
|
||||
* @param {[majorVersion: number, minorVersion: number, patchVersion: number]} require
|
||||
* @param {[majorVersion: number, minorVersion: number, patchVersion: number]} current
|
||||
* @returns
|
||||
*/
|
||||
function checkVersion(require, current) {
|
||||
// 防止不存在的意外,提前截断当前版本号的长度
|
||||
if (current.length > require.length) current.length = require.length;
|
||||
|
||||
|
@ -141,162 +294,5 @@ new Promise((resolve) => {
|
|||
if (current[i] > require[i]) return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
if (core in supportMap && !check(supportMap[core], versions)) {
|
||||
const tip =
|
||||
"检测到您的浏览器内核版本无法支持当前无名杀所需的功能,请立即升级浏览器或手机webview内核!";
|
||||
console.error(tip);
|
||||
let redirect_tip = `您使用的浏览器或无名杀客户端内核版本过低,已经无法正常运行无名杀!\n目前使用的浏览器UA信息为:\n${userAgent}\n点击“确认”以前往GitHub下载最新版无名杀客户端(可能需要科学上网)。\n稍后您的无名杀将自动退出(可能的话)`;
|
||||
if (core === "safari") {
|
||||
alert(
|
||||
`您使用的safari浏览器无法支持当前无名杀所需的功能,请至少升级至14.5.0!\n稍后您的无名杀将自动退出(可能的话)`
|
||||
);
|
||||
} else {
|
||||
if (confirm(redirect_tip)) {
|
||||
window.open(
|
||||
"https://github.com/libccy/noname/releases/tag/chromium77-client"
|
||||
);
|
||||
}
|
||||
}
|
||||
exit();
|
||||
} else {
|
||||
// node环境下
|
||||
if (
|
||||
typeof window.require == "function" &&
|
||||
typeof window.process == "object" &&
|
||||
typeof window.__dirname == "string"
|
||||
) {
|
||||
// 在http环境下修改__dirname和require的逻辑
|
||||
if (
|
||||
location.protocol.startsWith("http") &&
|
||||
window.__dirname.endsWith("electron.asar\\renderer")
|
||||
) {
|
||||
const path = require("path");
|
||||
window.__dirname = path.join(path.resolve(), "resources/app");
|
||||
const oldData = Object.entries(window.require);
|
||||
// @ts-ignore
|
||||
window.require = function (moduleId) {
|
||||
try {
|
||||
return module.require(moduleId);
|
||||
} catch {
|
||||
return module.require(
|
||||
path.join(window.__dirname, moduleId)
|
||||
);
|
||||
}
|
||||
};
|
||||
oldData.forEach(([key, value]) => {
|
||||
window.require[key] = value;
|
||||
});
|
||||
}
|
||||
// 增加导入ts的逻辑
|
||||
window.require.extensions[".ts"] = function (module, filename) {
|
||||
// @ts-ignore
|
||||
const _compile = module._compile;
|
||||
// @ts-ignore
|
||||
module._compile = function (code, fileName) {
|
||||
/**
|
||||
* @type { import('typescript') }
|
||||
*/
|
||||
// @ts-ignore
|
||||
const ts = require("./game/typescript.js");
|
||||
// 使用ts compiler对ts文件进行编译
|
||||
const result = ts.transpile(
|
||||
code,
|
||||
{
|
||||
module: ts.ModuleKind.CommonJS,
|
||||
//@todo: ES2019 -> ES2020
|
||||
target: ts.ScriptTarget.ES2019,
|
||||
inlineSourceMap: true,
|
||||
resolveJsonModule: true,
|
||||
esModuleInterop: true,
|
||||
},
|
||||
fileName
|
||||
);
|
||||
// 使用默认的js编译函数获取返回值
|
||||
return _compile.call(this, result, fileName);
|
||||
};
|
||||
// @ts-ignore
|
||||
module._compile(
|
||||
require("fs").readFileSync(filename, "utf8"),
|
||||
filename
|
||||
);
|
||||
};
|
||||
}
|
||||
// 使serviceWorker加载完成后,再加载entry.js
|
||||
const loadEntryJs = () => {
|
||||
const script = document.createElement("script");
|
||||
script.type = "module";
|
||||
script.src = `${assetURL}game/entry.js`;
|
||||
script.async = true;
|
||||
script.onerror = (event) => {
|
||||
console.error(event);
|
||||
const message = `您使用的浏览器或《无名杀》客户端加载内容失败!\n请检查是否缺少游戏文件!隔版本更新请下载完整包而不是离线包!\n目前使用的浏览器UA信息为:\n${userAgent}\n若您使用的客户端为自带内核的旧版“兼容版”,请及时更新客户端版本!\n若您使用的客户端为手机端的非兼容版《无名杀》,请尝试更新手机的WebView内核,或者更换为1.8.2版本及以上的兼容版!\n若您是直接使用浏览器加载index.html进行游戏,请改为运行文件夹内的“noname-server.exe”(或使用VSCode等工具启动Live Server),以动态服务器的方式启动《无名杀》!\n若您使用的是苹果端,请至少将Safari升级至14.5.0!`;
|
||||
console.error(message);
|
||||
alert(message);
|
||||
exit();
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
};
|
||||
|
||||
if (
|
||||
location.protocol.startsWith("http") &&
|
||||
"serviceWorker" in navigator
|
||||
) {
|
||||
let scope =
|
||||
window.location.protocol + "//" + window.location.host + window.location.pathname;
|
||||
navigator.serviceWorker
|
||||
.getRegistrations()
|
||||
.then(async (registrations) => {
|
||||
let findServiceWorker = registrations.find(
|
||||
(registration) => {
|
||||
return (
|
||||
registration &&
|
||||
registration.active &&
|
||||
registration.active.scriptURL ==
|
||||
`${scope}service-worker.js`
|
||||
);
|
||||
}
|
||||
);
|
||||
try {
|
||||
const registration_1 =
|
||||
await navigator.serviceWorker.register(
|
||||
`${scope}service-worker.js`,
|
||||
{
|
||||
type: "module",
|
||||
updateViaCache: "all",
|
||||
scope,
|
||||
}
|
||||
);
|
||||
// 初次加载worker,需要重新启动一次
|
||||
if (!findServiceWorker) location.reload();
|
||||
// 接收消息,暂时没用到
|
||||
navigator.serviceWorker.addEventListener(
|
||||
"message",
|
||||
(e) => {
|
||||
console.log(e);
|
||||
}
|
||||
);
|
||||
registration_1
|
||||
.update()
|
||||
.catch((e) =>
|
||||
console.error("worker update失败", e)
|
||||
);
|
||||
if (!sessionStorage.getItem("canUseTs")) {
|
||||
await import("./canUse.ts")
|
||||
.then(({ text }) => console.log(text))
|
||||
.catch(() => {
|
||||
sessionStorage.setItem("canUseTs", "1");
|
||||
location.reload();
|
||||
});
|
||||
}
|
||||
} catch (e_1) {
|
||||
console.log("serviceWorker加载失败: ", e_1);
|
||||
}
|
||||
})
|
||||
.finally(loadEntryJs);
|
||||
} else {
|
||||
loadEntryJs();
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
|
@ -81,6 +81,7 @@ export class ChromePromiseErrorHandler {
|
|||
event.promise.catch((error) => {
|
||||
// 如果`error`是个错误,则继续处理
|
||||
if (error instanceof Error) {
|
||||
if (/Failed to fetch/.test(error.message) || /Failed to load because no supported source was found/.test(error.message)) return;
|
||||
// 如果已经处理过该错误,则不再处理
|
||||
if (this.#errorList.includes(error)) return;
|
||||
this.#errorList.push(error);
|
||||
|
|
|
@ -18,6 +18,8 @@ export class FirefoxPromiseErrorHandler {
|
|||
onHandle(event) {
|
||||
event.promise.catch((error) => {
|
||||
if (typeof error === "object" && error instanceof Error) {
|
||||
if (/Failed to fetch/.test(error.message) || /The media resource indicated by the src attribute or assigned media provider object was not suitable/.test(error.message)) return;
|
||||
|
||||
// Firefox在大环境下默认情况必须要那么多ts-ignore
|
||||
// @ts-ignore
|
||||
window.onerror(
|
||||
|
|
|
@ -20,6 +20,7 @@ export class UnknownPromiseErrorHandler {
|
|||
onHandle(event) {
|
||||
event.promise.catch((error) => {
|
||||
if (typeof error === "object" && error instanceof Error) {
|
||||
if (/Failed to fetch/.test(error.message)) return;
|
||||
// 很遗憾,因浏览器问题,你只能看到这一段
|
||||
throw error;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue