Commit e8d5123
fix(pwa): 離線閱讀頁誤判成「這個瀏覽器沒有離線儲存」 (#272)
#269 用「等 1200 毫秒再問 getRegistration()」判斷這個環境有沒有 service worker。
那個延遲太短:Chrome 會把 register() 排到頁面 load 之後才真的跑,而這一頁要載完
material 的 bundle 與字型,正式站實測到十二秒才問得出 registration。
500ms registration=undefined
1500ms registration=false
6000ms registration=false
12000ms registration=true
結果是一個好好的瀏覽器被告知「這個瀏覽器沒有提供離線儲存」,章節清單的已存比例
全部顯示 0,勾選框也停用,等於整頁的功能都被關掉。
改成輪詢等 registration 出現,上限三十秒。真的不註冊的環境不靠等待判斷:base.html
是唯一知道要不要註冊的地方(hostname 白名單),讓它把結論寫進
window.__anoniServiceWorker,管理頁看到 false 就直接放棄。那支在 body 尾端比管理頁
的程式晚執行,所以第一輪拿到 undefined 是正常的,繼續等就是。
兩種環境都實測過:localhost 兩秒內顯示完整狀態,127.0.0.2(不在白名單)立刻顯示
說明,不空等三十秒。
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent 81885ca commit e8d5123
2 files changed
Lines changed: 32 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
283 | 287 | | |
284 | 288 | | |
285 | 289 | | |
| |||
293 | 297 | | |
294 | 298 | | |
295 | 299 | | |
| 300 | + | |
296 | 301 | | |
297 | 302 | | |
298 | 303 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
231 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
232 | 254 | | |
233 | 255 | | |
234 | 256 | | |
235 | 257 | | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | 258 | | |
241 | 259 | | |
242 | 260 | | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
249 | 265 | | |
250 | 266 | | |
251 | 267 | | |
| |||
0 commit comments