chore(sw): 本地镜像禁用 Service Worker(自注销旧注册 + 置空游戏 SW 注册模块)
This commit is contained in:
1 parent
a34cae5474
commit
4d8cbd81d6
3 files changed
+29
-31
No files matched your search
+23
-13
@@ -254,22 +254,32 @@ const Server = http.createServer((Req, Res) => {
|
|||||||
Res.writeHead(200, { 'Content-Type': 'application/javascript; charset=utf-8' }).end('/* noop */\n');
|
Res.writeHead(200, { 'Content-Type': 'application/javascript; charset=utf-8' }).end('/* noop */\n');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// /hornet_sw.js:Service Worker 本体。放在根路径 + 放行 Service-Worker-Allowed,
|
// 本地镜像已禁用 Service Worker。
|
||||||
// 作用域才能覆盖 /,从而接管首页 / 发起的 /play/... 碎请求(unpacked 单包缓存)
|
// 对任何还在注册的旧 SW(hornet_sw / 游戏自带 service-worker.js)返回一份"自注销"脚本:
|
||||||
if (UrlPath.split('?')[0] === '/hornet_sw.js') {
|
// 浏览器下次更新检查拉到新脚本后会 activate → unregister() → 刷新受控页面,
|
||||||
const SwFile = path.join(ROOT, 'tools', 'hornet_sw.js');
|
// 避免旧 SW 的 fetch 拦截把导航请求搞成 "network error response"。
|
||||||
if (!fs.existsSync(SwFile)) {
|
const SwPath = UrlPath.split('?')[0];
|
||||||
Res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' }).end('hornet_sw.js not found');
|
if (SwPath === '/hornet_sw.js' || SwPath === '/service-worker.js' || SwPath === '/play/service-worker.js') {
|
||||||
return;
|
const SelfKill = [
|
||||||
}
|
"self.addEventListener('install', function () { self.skipWaiting(); });",
|
||||||
const Sw = fs.readFileSync(SwFile);
|
"self.addEventListener('activate', function (e) {",
|
||||||
|
" e.waitUntil(self.registration.unregister().then(function () {",
|
||||||
|
" return self.clients.matchAll({ type: 'window' });",
|
||||||
|
" }).then(function (cs) {",
|
||||||
|
" cs.forEach(function (c) { try { c.navigate(c.url); } catch (err) {} });",
|
||||||
|
" }));",
|
||||||
|
"});",
|
||||||
|
"// 不调用 respondWith:请求走浏览器默认网络,不做任何拦截",
|
||||||
|
"self.addEventListener('fetch', function () {});",
|
||||||
|
"",
|
||||||
|
].join('\n');
|
||||||
Res.writeHead(200, {
|
Res.writeHead(200, {
|
||||||
'Content-Type': 'application/javascript; charset=utf-8',
|
'Content-Type': 'application/javascript; charset=utf-8',
|
||||||
'Content-Length': Sw.length,
|
'Content-Length': Buffer.byteLength(SelfKill),
|
||||||
'Cache-Control': 'no-cache',
|
'Cache-Control': 'no-store',
|
||||||
'Service-Worker-Allowed': '/',
|
'Service-Worker-Allowed': '/',
|
||||||
'X-Hornet-Sw': 'local',
|
'X-Hornet-Sw': 'disabled',
|
||||||
}).end(Sw);
|
}).end(SelfKill);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// /ws_hook.js:页面内 window.WebSocket 抓包脚本(旁听,不改传输/不改模块加载)。
|
// /ws_hook.js:页面内 window.WebSocket 抓包脚本(旁听,不改传输/不改模块加载)。
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"version":"96833eb2b0cf8909","base":"/play/static/js/unpacked/","count":127,"files":{"module_00806.js":"// ============================================================\n// Module ID: 806\n// ============================================================\n;(window.__modules__ = window.__modules__ || {})[806] = (t, n, i) => {\n \"use strict\";\n var r = i(19487),\n e = {\n childContextTypes: !0,\n contextType: !0,\n contextTypes: !0,\n defaultProps: !0,\n displayName: !0,\n getDefaultProps: !0,\n getDerivedStateFromError: !0,\n getDerivedStateFromProps: !0,\n mixins: !0,\n propTypes: !0,\n type: !0,\n },\n u = { name: !0, length: !0, prototype: !0, caller: !0, callee: !0, arguments: !0, arity: !0 },\n s = { $$typeof: !0, compare: !0, defaultProps: !0, displayName: !0, propTypes: !0, type: !0 },\n o = {};\n function _(t) {\n return r.isMemo(t) ? s : o[t.$$typeof] || e;\n }\n ((o[r.ForwardRef] = { $$typeof: !0, render: !0, defaultProps: !0, displayName: !0, propTypes: !0 }),\n (o[r.Memo] = s));\n var h = Object.defineProperty,\n a = Object.getOwnPropertyNames,\n c = Object.getOwnPropertySymbols,\n l = Object.getOwnPropertyDescriptor,\n f = Object.getPrototypeOf,\n v = Object.prototype;\n t.exports = function t(n, i, r) {\n if (\"string\" != typeof i) {\n if (v) {\n var e = f(i);\n e && e !== v && t(n, e, r);\n }\n var s = a(i);\n c && (s = s.concat(c(i)));\n for (var o = _(n), p = _(i), w = 0; w < s.length; ++w) {\n var d = s[w];\n if (!(u[d] || (r && r[d]) || (p && p[d]) || (o && o[d]))) {\n var g = l(i, d);\n try {\n h(n, d, g);\n } catch (t) {}\n }\n }\n }\n return n;\n };\n};\n","module_00905.js":"// ============================================================\n// Module ID: 905\n// ============================================================\n;(window.__modules__ = window.__modules__ || {})[905] = (t) => {\n \"use strict\";\n t.exports = \"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED\";\n};\n","module_01510.js":"// ============================================================\n// Module ID: 1510\n// ============================================================\n;(window.__modules__ = window.__modules__ || {})[1510] = (t, n, i) => {\n !(function (t, n, i, r, e) {\n \"use strict\";\n var u,\n s,\n o,\n _,\n h,\n a,\n c,\n l,\n f,\n v,\n p,\n w,\n d,\n g,\n m,\n k,\n z = n.$_$.ob,\n b = n.$_$.w4,\n q = i.$_$.e,\n y = n.$_$.he,\n $ = n.$_$.xj,\n x = n.$_$.h5,\n j = n.$_$.o1,\n S = n.$_$.gd,\n C = i.$_$.d,\n E = n.$_$.r5,\n T = n.$_$.ud,\n I = i.$_$.f,\n A = n.$_$.nf,\n R = r.$_$.s1,\n P = e.$_$.n,\n N = n.$_$.rf,\n M = n.$_$.dd,\n O = n.$_$.sj,\n D = i.$_$.r,\n L = i.$_$.b,\n B = e.$_$.f,\n U = n.$_$.yb,\n F = n.$_$.c,\n G = e.$_$.f1,\n H = n.$_$.ge,\n W = e.$_$.l,\n V = n.$_$.nj,\n K = n.$_$.ke;\n function Y(t) {\n var n = t.zuy_1;\n if (null != n) return n;\n z(\"codec_appId\");\n }\n function X() {}\n function J() {}\n function Z(t) {\n var n = t.cuz_1;\n if (null != n) return n;\n z(\"codec_questToAchievementMap\");\n }\n function Q() {}\n function tt(t) {\n var n = t.fuz_1;\n if (null != n) return n;\n z(\"codec_itemIdMap\");\n }\n function nt() {}\n function it() {\n ((this.iuz_1 = new R(A(I), null)), (this.juz_1 = new R(A(P), null)));\n }\n function rt() {\n (B.call(this),\n (this.nuz_1 = new R(A(I), null)),\n (this.ouz_1 = new R(A(P), null)),\n (this.quz_1 = new O(-621796162, 1132145095)),\n (this.ruz_1 = new O(1635469714, 1785333818)),\n (this.suz_1 = new O(-773564903, 1989636776)),\n (this.tuz_1 = new O(497901439, 366177258)),\n this.tay(),\n (this.uuz_1 = this.quz_1));\n }\n function et(t) {\n var n = N;\n return t.xuz_1.e2b(\n t,\n M(\n \"protocol\",\n 1,\n n,\n function (t) {\n return et(t);\n },\n null,\n ),\n );\n }\n function ut() {\n ((this.xuz_1 = new R(A(I), null)), (this.zuz_1 = new O(-1272608814, 1097348888)));\n }\n function st() {\n return ((t = H(y(ot))), ot.call(t), t);\n var t;\n }\n function ot() {}\n function _t(t) {\n var n = N;\n return t.fv0_1.e2b(\n t,\n M(\n \"protocol\",\n 1,\n n,\n function (t) {\n return _t(t);\n },\n null,\n ),\n );\n }\n function ht(t) {\n var n = N;\n return t.gv0_1.e2b(\n t,\n M(\n \"modelRegistry\",\n Line truncated
|
{"version":"594803f26e3e89aa","base":"/play/static/js/unpacked/","count":127,"files":{"module_00806.js":"// ============================================================\n// Module ID: 806\n// ============================================================\n;(window.__modules__ = window.__modules__ || {})[806] = (t, n, i) => {\n \"use strict\";\n var r = i(19487),\n e = {\n childContextTypes: !0,\n contextType: !0,\n contextTypes: !0,\n defaultProps: !0,\n displayName: !0,\n getDefaultProps: !0,\n getDerivedStateFromError: !0,\n getDerivedStateFromProps: !0,\n mixins: !0,\n propTypes: !0,\n type: !0,\n },\n u = { name: !0, length: !0, prototype: !0, caller: !0, callee: !0, arguments: !0, arity: !0 },\n s = { $$typeof: !0, compare: !0, defaultProps: !0, displayName: !0, propTypes: !0, type: !0 },\n o = {};\n function _(t) {\n return r.isMemo(t) ? s : o[t.$$typeof] || e;\n }\n ((o[r.ForwardRef] = { $$typeof: !0, render: !0, defaultProps: !0, displayName: !0, propTypes: !0 }),\n (o[r.Memo] = s));\n var h = Object.defineProperty,\n a = Object.getOwnPropertyNames,\n c = Object.getOwnPropertySymbols,\n l = Object.getOwnPropertyDescriptor,\n f = Object.getPrototypeOf,\n v = Object.prototype;\n t.exports = function t(n, i, r) {\n if (\"string\" != typeof i) {\n if (v) {\n var e = f(i);\n e && e !== v && t(n, e, r);\n }\n var s = a(i);\n c && (s = s.concat(c(i)));\n for (var o = _(n), p = _(i), w = 0; w < s.length; ++w) {\n var d = s[w];\n if (!(u[d] || (r && r[d]) || (p && p[d]) || (o && o[d]))) {\n var g = l(i, d);\n try {\n h(n, d, g);\n } catch (t) {}\n }\n }\n }\n return n;\n };\n};\n","module_00905.js":"// ============================================================\n// Module ID: 905\n// ============================================================\n;(window.__modules__ = window.__modules__ || {})[905] = (t) => {\n \"use strict\";\n t.exports = \"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED\";\n};\n","module_01510.js":"// ============================================================\n// Module ID: 1510\n// ============================================================\n;(window.__modules__ = window.__modules__ || {})[1510] = (t, n, i) => {\n !(function (t, n, i, r, e) {\n \"use strict\";\n var u,\n s,\n o,\n _,\n h,\n a,\n c,\n l,\n f,\n v,\n p,\n w,\n d,\n g,\n m,\n k,\n z = n.$_$.ob,\n b = n.$_$.w4,\n q = i.$_$.e,\n y = n.$_$.he,\n $ = n.$_$.xj,\n x = n.$_$.h5,\n j = n.$_$.o1,\n S = n.$_$.gd,\n C = i.$_$.d,\n E = n.$_$.r5,\n T = n.$_$.ud,\n I = i.$_$.f,\n A = n.$_$.nf,\n R = r.$_$.s1,\n P = e.$_$.n,\n N = n.$_$.rf,\n M = n.$_$.dd,\n O = n.$_$.sj,\n D = i.$_$.r,\n L = i.$_$.b,\n B = e.$_$.f,\n U = n.$_$.yb,\n F = n.$_$.c,\n G = e.$_$.f1,\n H = n.$_$.ge,\n W = e.$_$.l,\n V = n.$_$.nj,\n K = n.$_$.ke;\n function Y(t) {\n var n = t.zuy_1;\n if (null != n) return n;\n z(\"codec_appId\");\n }\n function X() {}\n function J() {}\n function Z(t) {\n var n = t.cuz_1;\n if (null != n) return n;\n z(\"codec_questToAchievementMap\");\n }\n function Q() {}\n function tt(t) {\n var n = t.fuz_1;\n if (null != n) return n;\n z(\"codec_itemIdMap\");\n }\n function nt() {}\n function it() {\n ((this.iuz_1 = new R(A(I), null)), (this.juz_1 = new R(A(P), null)));\n }\n function rt() {\n (B.call(this),\n (this.nuz_1 = new R(A(I), null)),\n (this.ouz_1 = new R(A(P), null)),\n (this.quz_1 = new O(-621796162, 1132145095)),\n (this.ruz_1 = new O(1635469714, 1785333818)),\n (this.suz_1 = new O(-773564903, 1989636776)),\n (this.tuz_1 = new O(497901439, 366177258)),\n this.tay(),\n (this.uuz_1 = this.quz_1));\n }\n function et(t) {\n var n = N;\n return t.xuz_1.e2b(\n t,\n M(\n \"protocol\",\n 1,\n n,\n function (t) {\n return et(t);\n },\n null,\n ),\n );\n }\n function ut() {\n ((this.xuz_1 = new R(A(I), null)), (this.zuz_1 = new O(-1272608814, 1097348888)));\n }\n function st() {\n return ((t = H(y(ot))), ot.call(t), t);\n var t;\n }\n function ot() {}\n function _t(t) {\n var n = N;\n return t.fv0_1.e2b(\n t,\n M(\n \"protocol\",\n 1,\n n,\n function (t) {\n return _t(t);\n },\n null,\n ),\n );\n }\n function ht(t) {\n var n = N;\n return t.gv0_1.e2b(\n t,\n M(\n \"modelRegistry\",\n Line truncated
|
||||||
@@ -1,20 +1,8 @@
|
|||||||
// ============================================================
|
// ============================================================
|
||||||
// Module ID: 26482
|
// Module ID: 26482
|
||||||
// ============================================================
|
// ============================================================
|
||||||
;(window.__modules__ = window.__modules__ || {})[26482] = () => {
|
// 原逻辑:页面 load 后 navigator.serviceWorker.register("./service-worker.js")
|
||||||
if ((new URLSearchParams(window.location.search), "serviceWorker" in navigator))
|
// 本地镜像已禁用 Service Worker(SW 的 fetch 会拦截导航请求,导致
|
||||||
window.addEventListener("load", () => {
|
// "The FetchEvent for http://127.0.0.1:8080/ resulted in a network error response"),
|
||||||
navigator.serviceWorker
|
// 因此这里置空,不再注册。
|
||||||
.register("./service-worker.js")
|
;(window.__modules__ = window.__modules__ || {})[26482] = () => {};
|
||||||
.then((t) => {
|
|
||||||
console.log("SW registered: ", t);
|
|
||||||
})
|
|
||||||
.catch((t) => {
|
|
||||||
console.log("SW registration failed: ", t);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
else {
|
|
||||||
const t = document.querySelectorAll('[rel="manifest"]')[0];
|
|
||||||
void 0 !== t && t.remove();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Reference in new issue
Block a user