@@ -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 , {
@@ -46,18 +47,11 @@ export function activate(context: vscode.ExtensionContext) {
4647
4748 resolveDebugConfiguration ( folder : vscode . WorkspaceFolder | undefined , config : vscode . DebugConfiguration , token ?: vscode . CancellationToken ) : vscode . ProviderResult < vscode . DebugConfiguration > {
4849 if ( config && config . type == debuggerType ) {
50+ let targetUri : string = utils . getUrlFromConfig ( folder , config ) ;
4951 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 ) ;
52+ attach ( context , /* viaConfig= */ true , defaultUrl ) ;
53+ } else if ( config . request && config . request . localeCompare ( 'launch' , 'en' , { sensitivity : 'base' } ) == 0 ) {
54+ launch ( context , targetUri , config . chromePath ) ;
6155 }
6256 } else {
6357 vscode . window . showErrorMessage ( 'No supported launch config was found.' ) ;
@@ -84,21 +78,21 @@ async function launch(context: vscode.ExtensionContext, launchUrl?: string, chro
8478 return ;
8579 }
8680
87- utils . launchLocalChrome ( pathToChrome , port , 'about:blank' ) ;
81+ utils . launchLocalChrome ( pathToChrome , port , defaultUrl ) ;
8882 }
8983
9084 const target = JSON . parse ( await utils . getURL ( `http://${ hostname } :${ port } /json/new?${ launchUrl } ` ) ) ;
9185
9286 if ( ! target || ! target . webSocketDebuggerUrl || target . webSocketDebuggerUrl == '' ) {
9387 vscode . window . showErrorMessage ( `Could not find the launched Chrome tab: (${ launchUrl } ).` ) ;
9488 telemetryReporter . sendTelemetryEvent ( 'launch/error/tab_not_found' , telemetryProps ) ;
95- attach ( context , viaConfig ) ;
89+ attach ( context , viaConfig , defaultUrl ) ;
9690 } else {
9791 DevToolsPanel . createOrShow ( context , target . webSocketDebuggerUrl ) ;
9892 }
9993}
10094
101- async function attach ( context : vscode . ExtensionContext , viaConfig : boolean ) {
95+ async function attach ( context : vscode . ExtensionContext , viaConfig : boolean , targetUrl : string ) {
10296 const telemetryProps = { viaConfig : `${ viaConfig } ` } ;
10397 telemetryReporter . sendTelemetryEvent ( 'attach' , telemetryProps ) ;
10498
@@ -111,14 +105,34 @@ async function attach(context: vscode.ExtensionContext, viaConfig: boolean) {
111105
112106 responseArray . forEach ( i => {
113107 i = utils . fixRemoteUrl ( hostname , port , i ) ;
114- items . push ( { label : i . title , description : i . url , detail : i . webSocketDebuggerUrl } ) ;
108+ items . push ( {
109+ label : i . title ,
110+ description : i . url ,
111+ detail : i . webSocketDebuggerUrl
112+ } ) ;
115113 } ) ;
116114
117- vscode . window . showQuickPick ( items ) . then ( ( selection ) => {
118- if ( selection ) {
119- DevToolsPanel . createOrShow ( context , selection . detail as string ) ;
115+ let targetUrl : string = '' ;
116+ let targetMatch :boolean = false ;
117+ if ( typeof targetUrl === 'string' && targetUrl . length > 0 && targetUrl != defaultUrl ) {
118+ const matches = items . filter ( i => i . description == defaultUrl ) ;
119+ if ( matches && matches . length > 0 ) {
120+ targetUrl = matches [ 0 ] . description ;
121+ targetMatch = true ;
122+ } else {
123+ vscode . window . showErrorMessage ( `Couldn't attach to ${ targetUrl } .` ) ;
120124 }
121- } ) ;
125+ }
126+
127+ if ( targetMatch ) {
128+ DevToolsPanel . createOrShow ( context , targetUrl as string ) ;
129+ } else {
130+ vscode . window . showQuickPick ( items ) . then ( ( selection ) => {
131+ if ( selection ) {
132+ DevToolsPanel . createOrShow ( context , selection . detail as string ) ;
133+ }
134+ } ) ;
135+ }
122136 } else {
123137 telemetryReporter . sendTelemetryEvent ( 'attach/error/no_json_array' , telemetryProps ) ;
124138 }
@@ -331,10 +345,10 @@ class DevToolsPanel {
331345 private _getDevtoolsState ( ) {
332346 const allPrefsKey = 'devtools-preferences' ;
333347 const allPrefs : any = this . _context . workspaceState . get ( allPrefsKey ) ||
334- {
335- uiTheme : '"dark"' ,
336- screencastEnabled : false
337- } ;
348+ {
349+ uiTheme : '"dark"' ,
350+ screencastEnabled : false
351+ } ;
338352 this . _panel . webview . postMessage ( `preferences:${ JSON . stringify ( allPrefs ) } ` ) ;
339353 }
340354
@@ -359,7 +373,7 @@ class DevToolsPanel {
359373 content = '' ;
360374 }
361375
362- this . _panel . webview . postMessage ( `setUrl:${ JSON . stringify ( { id : request . id , content} ) } ` ) ;
376+ this . _panel . webview . postMessage ( `setUrl:${ JSON . stringify ( { id : request . id , content } ) } ` ) ;
363377 }
364378
365379 private _update ( ) {
0 commit comments