@@ -12,6 +12,7 @@ interface IPackageInfo {
1212}
1313
1414const debuggerType : string = 'devtools-for-chrome' ;
15+ const defaultUrl : string = 'about:blank' ;
1516let telemetryReporter : TelemetryReporter ;
1617
1718export function activate ( context : vscode . ExtensionContext ) {
@@ -31,7 +32,7 @@ export function activate(context: vscode.ExtensionContext) {
3132 } ) ) ;
3233
3334 context . subscriptions . push ( vscode . commands . registerCommand ( 'devtools-for-chrome.attach' , async ( ) => {
34- attach ( context , /* viaConfig= */ false ) ;
35+ attach ( context , /* viaConfig= */ false , defaultUrl ) ;
3536 } ) ) ;
3637
3738 vscode . debug . registerDebugConfigurationProvider ( debuggerType , {
@@ -45,22 +46,18 @@ export function activate(context: vscode.ExtensionContext) {
4546 } ,
4647
4748 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' ) ;
6157 }
6258 } else {
6359 vscode . window . showErrorMessage ( 'No supported launch config was found.' ) ;
60+ telemetryReporter . sendTelemetryEvent ( 'launch/error/config_not_found' ) ;
6461 }
6562 return ;
6663 }
@@ -84,21 +81,21 @@ async function launch(context: vscode.ExtensionContext, launchUrl?: string, chro
8481 return ;
8582 }
8683
87- utils . launchLocalChrome ( pathToChrome , port , 'about:blank' ) ;
84+ utils . launchLocalChrome ( pathToChrome , port , defaultUrl ) ;
8885 }
8986
9087 const target = JSON . parse ( await utils . getURL ( `http://${ hostname } :${ port } /json/new?${ launchUrl } ` ) ) ;
9188
92- if ( ! target || ! target . webSocketDebuggerUrl || target . webSocketDebuggerUrl == '' ) {
89+ if ( ! target || ! target . webSocketDebuggerUrl || target . webSocketDebuggerUrl === '' ) {
9390 vscode . window . showErrorMessage ( `Could not find the launched Chrome tab: (${ launchUrl } ).` ) ;
9491 telemetryReporter . sendTelemetryEvent ( 'launch/error/tab_not_found' , telemetryProps ) ;
95- attach ( context , viaConfig ) ;
92+ attach ( context , viaConfig , defaultUrl ) ;
9693 } else {
9794 DevToolsPanel . createOrShow ( context , target . webSocketDebuggerUrl ) ;
9895 }
9996}
10097
101- async function attach ( context : vscode . ExtensionContext , viaConfig : boolean ) {
98+ async function attach ( context : vscode . ExtensionContext , viaConfig : boolean , targetUrl : string ) {
10299 const telemetryProps = { viaConfig : `${ viaConfig } ` } ;
103100 telemetryReporter . sendTelemetryEvent ( 'attach' , telemetryProps ) ;
104101
@@ -111,14 +108,32 @@ async function attach(context: vscode.ExtensionContext, viaConfig: boolean) {
111108
112109 responseArray . forEach ( i => {
113110 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+ } ) ;
115116 } ) ;
116117
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 } .` ) ;
120125 }
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+ }
122137 } else {
123138 telemetryReporter . sendTelemetryEvent ( 'attach/error/no_json_array' , telemetryProps ) ;
124139 }
@@ -331,10 +346,10 @@ class DevToolsPanel {
331346 private _getDevtoolsState ( ) {
332347 const allPrefsKey = 'devtools-preferences' ;
333348 const allPrefs : any = this . _context . workspaceState . get ( allPrefsKey ) ||
334- {
335- uiTheme : '"dark"' ,
336- screencastEnabled : false
337- } ;
349+ {
350+ uiTheme : '"dark"' ,
351+ screencastEnabled : false
352+ } ;
338353 this . _panel . webview . postMessage ( `preferences:${ JSON . stringify ( allPrefs ) } ` ) ;
339354 }
340355
@@ -359,7 +374,7 @@ class DevToolsPanel {
359374 content = '' ;
360375 }
361376
362- this . _panel . webview . postMessage ( `setUrl:${ JSON . stringify ( { id : request . id , content} ) } ` ) ;
377+ this . _panel . webview . postMessage ( `setUrl:${ JSON . stringify ( { id : request . id , content } ) } ` ) ;
363378 }
364379
365380 private _update ( ) {
0 commit comments