@@ -12,6 +12,7 @@ interface IPackageInfo {
12
12
}
13
13
14
14
const debuggerType : string = 'devtools-for-chrome' ;
15
+ const defaultUrl : string = 'about:blank' ;
15
16
let telemetryReporter : TelemetryReporter ;
16
17
17
18
export function activate ( context : vscode . ExtensionContext ) {
@@ -31,7 +32,7 @@ export function activate(context: vscode.ExtensionContext) {
31
32
} ) ) ;
32
33
33
34
context . subscriptions . push ( vscode . commands . registerCommand ( 'devtools-for-chrome.attach' , async ( ) => {
34
- attach ( context , /* viaConfig= */ false ) ;
35
+ attach ( context , /* viaConfig= */ false , defaultUrl ) ;
35
36
} ) ) ;
36
37
37
38
vscode . debug . registerDebugConfigurationProvider ( debuggerType , {
@@ -45,22 +46,18 @@ export function activate(context: vscode.ExtensionContext) {
45
46
} ,
46
47
47
48
resolveDebugConfiguration ( folder : vscode . WorkspaceFolder | undefined , config : vscode . DebugConfiguration , token ?: vscode . CancellationToken ) : vscode . ProviderResult < vscode . DebugConfiguration > {
48
- if ( config && config . type == debuggerType ) {
49
- if ( config . request && config . request . localeCompare ( 'attach' , 'en' , { sensitivity : 'base' } ) == 0 ) {
50
- attach ( context , /* viaConfig= */ true ) ;
51
- } else {
52
- let launchUri : string = '' ;
53
- if ( folder . uri . scheme == 'file' ) {
54
- const baseUrl : string = config . file || config . url ;
55
- const replacedUri : string = baseUrl . replace ( '${workspaceFolder}' , folder . uri . path ) ;
56
- launchUri = utils . pathToFileURL ( replacedUri ) ;
57
- } else {
58
- launchUri = config . url ;
59
- }
60
- launch ( context , launchUri , config . chromePath ) ;
49
+ if ( config && config . type === debuggerType ) {
50
+ const targetUri : string = utils . getUrlFromConfig ( folder , config ) ;
51
+ if ( config . request && config . request . localeCompare ( 'attach' , 'en' , { sensitivity : 'base' } ) === 0 ) {
52
+ attach ( context , /* viaConfig= */ true , targetUri ) ;
53
+ telemetryReporter . sendTelemetryEvent ( 'launch/command/attach' ) ;
54
+ } else if ( config . request && config . request . localeCompare ( 'launch' , 'en' , { sensitivity : 'base' } ) === 0 ) {
55
+ launch ( context , targetUri , config . chromePath ) ;
56
+ telemetryReporter . sendTelemetryEvent ( 'launch/command/launch' ) ;
61
57
}
62
58
} else {
63
59
vscode . window . showErrorMessage ( 'No supported launch config was found.' ) ;
60
+ telemetryReporter . sendTelemetryEvent ( 'launch/error/config_not_found' ) ;
64
61
}
65
62
return ;
66
63
}
@@ -84,21 +81,21 @@ async function launch(context: vscode.ExtensionContext, launchUrl?: string, chro
84
81
return ;
85
82
}
86
83
87
- utils . launchLocalChrome ( pathToChrome , port , 'about:blank' ) ;
84
+ utils . launchLocalChrome ( pathToChrome , port , defaultUrl ) ;
88
85
}
89
86
90
87
const target = JSON . parse ( await utils . getURL ( `http://${ hostname } :${ port } /json/new?${ launchUrl } ` ) ) ;
91
88
92
- if ( ! target || ! target . webSocketDebuggerUrl || target . webSocketDebuggerUrl == '' ) {
89
+ if ( ! target || ! target . webSocketDebuggerUrl || target . webSocketDebuggerUrl === '' ) {
93
90
vscode . window . showErrorMessage ( `Could not find the launched Chrome tab: (${ launchUrl } ).` ) ;
94
91
telemetryReporter . sendTelemetryEvent ( 'launch/error/tab_not_found' , telemetryProps ) ;
95
- attach ( context , viaConfig ) ;
92
+ attach ( context , viaConfig , defaultUrl ) ;
96
93
} else {
97
94
DevToolsPanel . createOrShow ( context , target . webSocketDebuggerUrl ) ;
98
95
}
99
96
}
100
97
101
- async function attach ( context : vscode . ExtensionContext , viaConfig : boolean ) {
98
+ async function attach ( context : vscode . ExtensionContext , viaConfig : boolean , targetUrl : string ) {
102
99
const telemetryProps = { viaConfig : `${ viaConfig } ` } ;
103
100
telemetryReporter . sendTelemetryEvent ( 'attach' , telemetryProps ) ;
104
101
@@ -111,14 +108,32 @@ async function attach(context: vscode.ExtensionContext, viaConfig: boolean) {
111
108
112
109
responseArray . forEach ( i => {
113
110
i = utils . fixRemoteUrl ( hostname , port , i ) ;
114
- items . push ( { label : i . title , description : i . url , detail : i . webSocketDebuggerUrl } ) ;
111
+ items . push ( {
112
+ label : i . title ,
113
+ description : i . url ,
114
+ detail : i . webSocketDebuggerUrl
115
+ } ) ;
115
116
} ) ;
116
117
117
- vscode . window . showQuickPick ( items ) . then ( ( selection ) => {
118
- if ( selection ) {
119
- DevToolsPanel . createOrShow ( context , selection . detail as string ) ;
118
+ let targetWebsocketUrl = '' ;
119
+ if ( typeof targetUrl === 'string' && targetUrl . length > 0 && targetUrl !== defaultUrl ) {
120
+ const matches = items . filter ( i => targetUrl . localeCompare ( i . description , 'en' , { sensitivity : 'base' } ) === 0 ) ;
121
+ if ( matches && matches . length > 0 ) {
122
+ targetWebsocketUrl = matches [ 0 ] . detail ;
123
+ } else {
124
+ vscode . window . showErrorMessage ( `Couldn't attach to ${ targetUrl } .` ) ;
120
125
}
121
- } ) ;
126
+ }
127
+
128
+ if ( targetWebsocketUrl && targetWebsocketUrl . length > 0 ) {
129
+ DevToolsPanel . createOrShow ( context , targetWebsocketUrl as string ) ;
130
+ } else {
131
+ vscode . window . showQuickPick ( items ) . then ( ( selection ) => {
132
+ if ( selection ) {
133
+ DevToolsPanel . createOrShow ( context , selection . detail as string ) ;
134
+ }
135
+ } ) ;
136
+ }
122
137
} else {
123
138
telemetryReporter . sendTelemetryEvent ( 'attach/error/no_json_array' , telemetryProps ) ;
124
139
}
@@ -331,10 +346,10 @@ class DevToolsPanel {
331
346
private _getDevtoolsState ( ) {
332
347
const allPrefsKey = 'devtools-preferences' ;
333
348
const allPrefs : any = this . _context . workspaceState . get ( allPrefsKey ) ||
334
- {
335
- uiTheme : '"dark"' ,
336
- screencastEnabled : false
337
- } ;
349
+ {
350
+ uiTheme : '"dark"' ,
351
+ screencastEnabled : false
352
+ } ;
338
353
this . _panel . webview . postMessage ( `preferences:${ JSON . stringify ( allPrefs ) } ` ) ;
339
354
}
340
355
@@ -359,7 +374,7 @@ class DevToolsPanel {
359
374
content = '' ;
360
375
}
361
376
362
- this . _panel . webview . postMessage ( `setUrl:${ JSON . stringify ( { id : request . id , content} ) } ` ) ;
377
+ this . _panel . webview . postMessage ( `setUrl:${ JSON . stringify ( { id : request . id , content } ) } ` ) ;
363
378
}
364
379
365
380
private _update ( ) {
0 commit comments