@@ -156,6 +156,8 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
156
156
157
157
public readonly events : StepProgressEventsEmitter ;
158
158
159
+ private _loadedSourcesByScriptId = new Map < Crdp . Runtime . ScriptId , CrdpScript > ( ) ;
160
+
159
161
public constructor ( { chromeConnection, lineColTransformer, sourceMapTransformer, pathTransformer, targetFilter, enableSourceMapCaching } : IChromeDebugAdapterOpts ,
160
162
session : ChromeDebugSession ) {
161
163
telemetry . setupEventHandler ( e => session . sendEvent ( e ) ) ;
@@ -599,7 +601,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
599
601
* e.g. the target navigated
600
602
*/
601
603
protected onExecutionContextsCleared ( ) : Promise < void > {
602
- const cachedScriptParsedEvents = Array . from ( this . _scriptsById . values ( ) ) ;
604
+ const cachedScriptParsedEvents = Array . from ( this . _loadedSourcesByScriptId . values ( ) ) ;
603
605
this . clearTargetContext ( ) ;
604
606
return this . doAfterProcessingSourceEvents ( async ( ) => { // This will not execute until all the on-flight 'new' source events have been processed
605
607
for ( let scriptedParseEvent of cachedScriptParsedEvents ) {
@@ -856,7 +858,28 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
856
858
}
857
859
858
860
protected async sendLoadedSourceEvent ( script : Crdp . Debugger . ScriptParsedEvent , loadedSourceEventReason : LoadedSourceEventReason = 'new' ) : Promise < void > {
861
+ switch ( loadedSourceEventReason ) {
862
+ case 'new' :
863
+ case 'changed' :
864
+ if ( this . _loadedSourcesByScriptId . get ( script . scriptId ) ) {
865
+ loadedSourceEventReason = 'changed' ;
866
+ } else {
867
+ loadedSourceEventReason = 'new' ;
868
+ }
869
+ this . _loadedSourcesByScriptId . set ( script . scriptId , script ) ;
870
+ break ;
871
+ case 'removed' :
872
+ if ( ! this . _loadedSourcesByScriptId . delete ( script . scriptId ) ) {
873
+ telemetry . reportEvent ( 'LoadedSourceEventError' , { issue : 'Tried to remove non-existent script' , scriptId : script . scriptId } ) ;
874
+ return ;
875
+ }
876
+ break ;
877
+ default :
878
+ telemetry . reportEvent ( 'LoadedSourceEventError' , { issue : 'Unknown reason' , reason : loadedSourceEventReason } ) ;
879
+ }
880
+
859
881
const scriptEvent = await this . scriptToLoadedSourceEvent ( loadedSourceEventReason , script ) ;
882
+
860
883
this . _session . sendEvent ( scriptEvent ) ;
861
884
}
862
885
0 commit comments