File tree 1 file changed +14
-7
lines changed
1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -50,13 +50,20 @@ registerRoute(
50
50
// Offline fallback
51
51
self . addEventListener ( 'install' , ( event : ExtendableEvent ) => {
52
52
const offlineFallbackPage = new Request ( '/offline.html' ) ;
53
- event . waitUntil (
54
- fetch ( offlineFallbackPage ) . then ( response => {
55
- return caches . open ( 'offline' ) . then ( cache => {
56
- return cache . put ( offlineFallbackPage , response ) ;
57
- } ) ;
58
- } )
59
- ) ;
53
+
54
+ // Using an async function to handle the install event
55
+ const installHandler = async ( ) => {
56
+ try {
57
+ const response = await fetch ( offlineFallbackPage ) ;
58
+ const cache = await caches . open ( 'offline' ) ;
59
+ await cache . put ( offlineFallbackPage , response ) ;
60
+ } catch ( error ) {
61
+ console . error ( 'Failed to cache offline page:' , error ) ;
62
+ }
63
+ } ;
64
+
65
+ // Wait until the async function completes
66
+ event . waitUntil ( installHandler ( ) ) ;
60
67
} ) ;
61
68
62
69
export { } ; // This helps with module augmentation
You can’t perform that action at this time.
0 commit comments