let dataCacheName = "graphs-v1" ; let filesToCache = [ "index.html" ] ; const ctx = self as any ; ctx . addEventListener ( "install" , ( event ) => { event . waitUntil ( caches . open ( dataCacheName ) . then ( cache => cache . addAll ( filesToCache ) ) . then ( ( ) => ctx . skipWaiting ( ) ) ) ; } ) ; ctx . addEventListener ( "activate" , ( ) => { ctx . clients . claim ( ) ; } ) ; ctx . addEventListener ( "fetch" , ( event ) => { event . respondWith ( fetch ( event . request ) . then ( response => { if ( event . request . url . includes ( "chrome-extension://" ) ) { return response ; } return caches . open ( dataCacheName ) . then ( cache => { const newResp = response . clone ( ) ; if ( ! newResp . url . includes ( "data:" ) && event . request . method === "GET" ) { cache . put ( event . request , newResp ) ; } return response ; } ) ; } ) . catch ( ( ) => { return caches . match ( event . request ) as Promise < Response > ; } ) ) ; } ) ;