1414 * limitations under the License.
1515 */
1616
17- import * as idbKeyval from 'idb-keyval' ;
18-
1917import { splitProgress } from './progress' ;
2018import { unwrapPopoutUrl } from './snapshotRenderer' ;
2119import { SnapshotServer } from './snapshotServer' ;
@@ -35,13 +33,10 @@ self.addEventListener('activate', function(event: any) {
3533} ) ;
3634
3735const scopePath = new URL ( self . registration . scope ) . pathname ;
36+
3837const loadedTraces = new Map < string , { traceModel : TraceModel , snapshotServer : SnapshotServer } > ( ) ;
39- const clientIdToTraceUrls = new Map < string , { limit : number | undefined , traceUrls : Set < string > , traceViewerServer : TraceViewerServer } > ( ) ;
4038
41- function simulateServiceWorkerRestart ( ) {
42- loadedTraces . clear ( ) ;
43- clientIdToTraceUrls . clear ( ) ;
44- }
39+ const clientIdToTraceUrls = new Map < string , { limit : number | undefined , traceUrls : Set < string > , traceViewerServer : TraceViewerServer } > ( ) ;
4540
4641async function loadTrace ( traceUrl : string , traceFileName : string | null , client : any | undefined , limit : number | undefined , progress : ( done : number , total : number ) => undefined ) : Promise < TraceModel > {
4742 await gc ( ) ;
@@ -54,7 +49,6 @@ async function loadTrace(traceUrl: string, traceFileName: string | null, client:
5449 clientIdToTraceUrls . set ( clientId , data ) ;
5550 }
5651 data . traceUrls . add ( traceUrl ) ;
57- await saveClientIdParams ( ) ;
5852
5953 const traceModel = new TraceModel ( ) ;
6054 try {
@@ -107,10 +101,6 @@ async function doFetch(event: FetchEvent): Promise<Response> {
107101 await gc ( ) ;
108102 return new Response ( null , { status : 200 } ) ;
109103 }
110- if ( relativePath === '/restartServiceWorker' ) {
111- simulateServiceWorkerRestart ( ) ;
112- return new Response ( null , { status : 200 } ) ;
113- }
114104
115105 const traceUrl = url . searchParams . get ( 'trace' ) ;
116106
@@ -132,16 +122,6 @@ async function doFetch(event: FetchEvent): Promise<Response> {
132122 }
133123 }
134124
135- if ( ! clientIdToTraceUrls . has ( event . clientId ) ) {
136- // Service worker was restarted upon subresource fetch.
137- // It was stopped because ping did not keep it alive since the tab itself was throttled.
138- const params = await loadClientIdParams ( event . clientId ) ;
139- if ( params ) {
140- for ( const traceUrl of params . traceUrls )
141- await loadTrace ( traceUrl , null , client , params . limit , ( ) => { } ) ;
142- }
143- }
144-
145125 if ( relativePath . startsWith ( '/snapshotInfo/' ) ) {
146126 const { snapshotServer } = loadedTraces . get ( traceUrl ! ) || { } ;
147127 if ( ! snapshotServer )
@@ -241,36 +221,6 @@ async function gc() {
241221 if ( ! usedTraces . has ( traceUrl ) )
242222 loadedTraces . delete ( traceUrl ) ;
243223 }
244-
245- await saveClientIdParams ( ) ;
246- }
247-
248- // Persist clientIdToTraceUrls to localStorage to avoid losing it when the service worker is restarted.
249- async function saveClientIdParams ( ) {
250- const serialized : Record < string , {
251- limit : number | undefined ,
252- traceUrls : string [ ]
253- } > = { } ;
254- for ( const [ clientId , data ] of clientIdToTraceUrls ) {
255- serialized [ clientId ] = {
256- limit : data . limit ,
257- traceUrls : [ ...data . traceUrls ]
258- } ;
259- }
260-
261- const newValue = JSON . stringify ( serialized ) ;
262- const oldValue = await idbKeyval . get ( 'clientIdToTraceUrls' ) ;
263- if ( newValue === oldValue )
264- return ;
265- idbKeyval . set ( 'clientIdToTraceUrls' , newValue ) ;
266- }
267-
268- async function loadClientIdParams ( clientId : string ) : Promise < { limit : number | undefined , traceUrls : string [ ] } | undefined > {
269- const serialized = await idbKeyval . get ( 'clientIdToTraceUrls' ) as string | undefined ;
270- if ( ! serialized )
271- return ;
272- const deserialized = JSON . parse ( serialized ) ;
273- return deserialized [ clientId ] ;
274224}
275225
276226// @ts -ignore
0 commit comments