sw.js 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. importScripts("/dist/precache-manifest.bb9fed9fcf675d916091b53a1d3c6a09.js");
  2. var workbox=function(){"use strict";try{self.workbox.v["workbox:sw:3.6.3"]=1}catch(t){}const t="https://storage.googleapis.com/workbox-cdn/releases/3.6.3",e={backgroundSync:"background-sync",broadcastUpdate:"broadcast-cache-update",cacheableResponse:"cacheable-response",core:"core",expiration:"cache-expiration",googleAnalytics:"google-analytics",navigationPreload:"navigation-preload",precaching:"precaching",rangeRequests:"range-requests",routing:"routing",strategies:"strategies",streams:"streams"};return new class{constructor(){return this.v={},this.t={debug:"localhost"===self.location.hostname,modulePathPrefix:null,modulePathCb:null},this.e=this.t.debug?"dev":"prod",this.s=!1,new Proxy(this,{get(t,s){if(t[s])return t[s];const o=e[s];return o&&t.loadModule(`workbox-${o}`),t[s]}})}setConfig(t={}){if(this.s)throw new Error("Config must be set before accessing workbox.* modules");Object.assign(this.t,t),this.e=this.t.debug?"dev":"prod"}skipWaiting(){self.addEventListener("install",()=>self.skipWaiting())}clientsClaim(){self.addEventListener("activate",()=>self.clients.claim())}loadModule(t){const e=this.o(t);try{importScripts(e),this.s=!0}catch(s){throw console.error(`Unable to import module '${t}' from '${e}'.`),s}}o(e){if(this.t.modulePathCb)return this.t.modulePathCb(e,this.t.debug);let s=[t];const o=`${e}.${this.e}.js`,r=this.t.modulePathPrefix;return r&&""===(s=r.split("/"))[s.length-1]&&s.splice(s.length-1,1),s.push(o),s.join("/")}}}();
  3. workbox.core.setCacheNameDetails({ prefix: 'MeeChat' })
  4. /**
  5. * The workboxSW.precacheAndRoute() method efficiently caches and responds to
  6. * requests for URLs in the manifest.
  7. * See https://goo.gl/S9QRab
  8. */
  9. self.__precacheManifest = [].concat(self.__precacheManifest || [])
  10. workbox.precaching.suppressWarnings()
  11. workbox.precaching.precacheAndRoute(self.__precacheManifest, {
  12. directoryIndex: null
  13. })
  14. // const CACHE_NAME = 'mySiteCache';
  15. // let urlsToCache = [
  16. // '/',
  17. // ];
  18. // self.addEventListener('install', function (event) {
  19. // console.log('[ServiceWorker] install')
  20. // // event.waitUntil(
  21. // // caches.open(CACHE_NAME).then(function(caches){
  22. // // console.log('open cache:' + caches);
  23. // // return caches.addAll(urlsToCache);
  24. // // })
  25. // // )
  26. // })
  27. // self.addEventListener('activate', function (event) {
  28. // console.log('[ServiceWorker] activate')
  29. // // const cacheWhitelist = ['pagesCache', 'blogPostsCache'];
  30. // // event.waitUntil(
  31. // // caches.keys().then(function(cacheNames) {
  32. // // return Promise.all(
  33. // // cacheNames.map(function(cacheName) {
  34. // // if (cacheWhitelist.indexOf(cacheName) === -1) {
  35. // // return caches.delete(cacheName);
  36. // // }
  37. // // })
  38. // // );
  39. // // })
  40. // // );
  41. // })
  42. // self.addEventListener('fetch', function (event) {
  43. // console.log(event.request)
  44. // console.log('[ServiceWorker] Fetch', event.request.url)
  45. // })
  46. // self.addEventListener('error', function (event) {
  47. // console.log('[ServiceWorker] error', event)
  48. // })
  49. // self.addEventListener('push', function (event) {
  50. // // console.log('[Service Worker] 收到通知',event);
  51. // console.log(`[Service Worker] 收到的通知数据为: "${event.data.text()}"`)
  52. // function decodeUnicode (str) {
  53. // str = str.replace(/\\/g, '%')
  54. // str = unescape(str)
  55. // str = str.replace(/%/g, '\\')
  56. // str = str.replace(/\\/g, '')
  57. // return str
  58. // }
  59. // let data = JSON.parse(event.data.text())
  60. // const title = decodeUnicode(data.title)
  61. // const options = {
  62. // body: decodeUnicode(data.content),
  63. // icon: 'dice-logo.png'
  64. // }
  65. // event.waitUntil(self.registration.showNotification(title, options))
  66. // })
  67. // // 点击跳转
  68. // self.addEventListener('notificationclick', function (event) {
  69. // event.notification.close()
  70. // // event.waitUntil(
  71. // // clients.openWindow('https://mee.chat/')
  72. // // )
  73. // })