@andy.ian/dsh-homing 2.3.9 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client-report.js +38 -31
- package/package.json +1 -1
package/lib/client-report.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* 1. 捕获 window.onerror / unhandledrejection / 资源加载失败 → 立即上报
|
|
7
7
|
* 2. 捕获 console.error / console.warn 的前 2 条(插件初始化失败常被应用
|
|
8
8
|
* try/catch 后写 logger,window.onerror 看不到)
|
|
9
|
-
* 3.
|
|
9
|
+
* 3. 启动检测:只在连续 60 秒毫无加载进展时才提示,不自动重载
|
|
10
|
+
* (首次打开要下载约 3MB 脚本,慢网络下 20–40 秒属正常,别误报)
|
|
10
11
|
*
|
|
11
12
|
* 必须是外部文件(页面 CSP 只有 script-src 'self')。
|
|
12
13
|
*/
|
|
@@ -67,6 +68,16 @@
|
|
|
67
68
|
})
|
|
68
69
|
})
|
|
69
70
|
|
|
71
|
+
// 记录"还有进展":资源加载、DOM 状态变化、console 输出都会刷新它。
|
|
72
|
+
// 首次打开手机端要下载约 3MB(gzip 后)的 DSH 前端脚本,慢 networks 下
|
|
73
|
+
// 需要 20–40 秒;只要还在进展就耐心等,不能当成"卡住"(2026-11-23 实测:
|
|
74
|
+
// 旧的 12 秒检测会误报,还会自动重载把已下载的资源丢掉,反而更慢)。
|
|
75
|
+
let lastProgressAt = Date.now()
|
|
76
|
+
const markProgress = () => { lastProgressAt = Date.now() }
|
|
77
|
+
window.addEventListener('load', markProgress, true)
|
|
78
|
+
window.addEventListener('error', markProgress, true)
|
|
79
|
+
document.addEventListener('readystatechange', markProgress, true)
|
|
80
|
+
|
|
70
81
|
// 只拦 error / warn,每级 2 条:足够定位插件初始化失败,又不影响性能
|
|
71
82
|
for (const level of ['error', 'warn']) {
|
|
72
83
|
const original = console[level]
|
|
@@ -74,6 +85,7 @@
|
|
|
74
85
|
let reported = 0
|
|
75
86
|
console[level] = function patched(...args) {
|
|
76
87
|
try {
|
|
88
|
+
markProgress()
|
|
77
89
|
if (reported < 2) {
|
|
78
90
|
reported += 1
|
|
79
91
|
report({
|
|
@@ -90,51 +102,46 @@
|
|
|
90
102
|
}
|
|
91
103
|
}
|
|
92
104
|
|
|
93
|
-
// 12
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
|
|
105
|
+
// 启动检测:12 秒后第一次检查,若仍在启动页:
|
|
106
|
+
// - 最近 60 秒内有任何加载进展 → 继续等(每 10 秒复查),不提示、不重载;
|
|
107
|
+
// - 连续 60 秒毫无进展 → 才上报并显示温和提示。
|
|
108
|
+
// 不再自动换 URL 重载:慢网络下重载会丢弃已经下好的资源,让首次打开更慢。
|
|
109
|
+
const BOOT_IDLE_LIMIT_MS = 60_000
|
|
110
|
+
const BOOT_RECHECK_MS = 10_000
|
|
111
|
+
|
|
112
|
+
function checkBoot() {
|
|
97
113
|
try {
|
|
98
114
|
const root = document.getElementById('root')
|
|
99
115
|
const splash = document.querySelector('[data-dsh-boot]')
|
|
100
116
|
const mounted = Boolean(root && root.childElementCount > 0) && !splash
|
|
101
|
-
if (mounted) return
|
|
117
|
+
if (mounted) return true
|
|
118
|
+
const idleMs = Date.now() - lastProgressAt
|
|
119
|
+
if (idleMs < BOOT_IDLE_LIMIT_MS) {
|
|
120
|
+
setTimeout(checkBoot, BOOT_RECHECK_MS)
|
|
121
|
+
return false
|
|
122
|
+
}
|
|
102
123
|
report({
|
|
103
124
|
kind: 'boot-timeout',
|
|
104
125
|
message: String(document.body?.innerText ?? '').replace(/\s+/g, ' ').slice(0, 400) || '(页面无文字)',
|
|
105
126
|
rootExists: Boolean(root),
|
|
106
127
|
splashPresent: Boolean(splash),
|
|
107
128
|
readyState: document.readyState,
|
|
129
|
+
idleMs,
|
|
108
130
|
})
|
|
109
|
-
|
|
110
|
-
// 自动重载:每次会话只尝试一次,避免死循环
|
|
111
|
-
let tried = false
|
|
112
|
-
try {
|
|
113
|
-
tried = sessionStorage.getItem('dsh-homing-boot-retry') === '1'
|
|
114
|
-
if (!tried) sessionStorage.setItem('dsh-homing-boot-retry', '1')
|
|
115
|
-
} catch (error) {
|
|
116
|
-
tried = true // 拿不到 sessionStorage 就不要再自动刷新
|
|
117
|
-
}
|
|
118
|
-
if (!tried) {
|
|
119
|
-
const url = new URL(location.href)
|
|
120
|
-
url.searchParams.set('_r', Date.now().toString(36))
|
|
121
|
-
location.replace(url.href)
|
|
122
|
-
return
|
|
123
|
-
}
|
|
124
|
-
|
|
125
131
|
showStuckOverlay()
|
|
126
132
|
} catch (error) {
|
|
127
133
|
// 忽略
|
|
128
134
|
}
|
|
129
|
-
|
|
135
|
+
return false
|
|
136
|
+
}
|
|
137
|
+
setTimeout(checkBoot, 12_000)
|
|
130
138
|
|
|
131
139
|
/**
|
|
132
|
-
*
|
|
140
|
+
* 真正长时间无进展时给出的提示。
|
|
133
141
|
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* 所以卡住时直接把这句话显示出来,配一个重新加载按钮。
|
|
142
|
+
* 注意措辞(2026-11-23 修正):首次打开要下载 DSH 前端约 3MB 脚本,慢网络
|
|
143
|
+
* 本来就要几十秒,不能一上来就让人"彻底关浏览器";只有在确认毫无进展时才
|
|
144
|
+
* 给出自救建议,且把"重新加载"作为首选而不是自动执行。
|
|
138
145
|
*/
|
|
139
146
|
function showStuckOverlay() {
|
|
140
147
|
if (document.getElementById('dsh-homing-stuck')) return
|
|
@@ -145,12 +152,12 @@
|
|
|
145
152
|
+ 'padding:14px;font:14px/1.6 system-ui,-apple-system,"Noto Sans SC",sans-serif;'
|
|
146
153
|
+ 'box-shadow:0 8px 28px rgba(0,0,0,.5)'
|
|
147
154
|
const title = document.createElement('div')
|
|
148
|
-
title.textContent = '
|
|
155
|
+
title.textContent = '页面加载较慢或暂时没有进展'
|
|
149
156
|
title.style.cssText = 'font-weight:700;margin-bottom:6px'
|
|
150
157
|
const hint = document.createElement('div')
|
|
151
158
|
hint.style.cssText = 'color:#b7bec9;margin-bottom:10px'
|
|
152
|
-
hint.textContent = '
|
|
153
|
-
+ '
|
|
159
|
+
hint.textContent = '首次打开需要下载约 3MB 的页面资源,网络慢时可能需要 30–60 秒。'
|
|
160
|
+
+ '如果一直不动,可先点「重新加载」;仍不行再在手机多任务里彻底关闭浏览器后重开。'
|
|
154
161
|
const row = document.createElement('div')
|
|
155
162
|
row.style.cssText = 'display:flex;gap:8px'
|
|
156
163
|
const reload = document.createElement('button')
|