@@ -3,7 +3,6 @@ import * as vscode from 'vscode';
33import WebSocket from 'ws' ;
44import QuickPickItem = vscode . QuickPickItem ;
55import * as utils from './utils' ;
6- import { isRegExp } from 'util' ;
76
87const settings = vscode . workspace . getConfiguration ( 'vscode-devtools-for-chrome' ) ;
98const hostname = settings . get ( 'hostname' ) as string || 'localhost' ;
@@ -24,50 +23,51 @@ export function activate(context: vscode.ExtensionContext) {
2423 attach ( context ) ;
2524 } ) ) ;
2625
27- vscode . debug . onDidStartDebugSession ( async ( e : vscode . DebugSession ) => {
28- //debugSessionStart(e, context);
29- } ) ;
30-
3126 vscode . debug . registerDebugConfigurationProvider ( debuggerType , {
3227 provideDebugConfigurations ( folder : vscode . WorkspaceFolder | undefined , token ?: vscode . CancellationToken ) : vscode . ProviderResult < vscode . DebugConfiguration [ ] > {
3328 return ;
3429 } ,
35-
30+
3631 resolveDebugConfiguration ( folder : vscode . WorkspaceFolder | undefined , config : vscode . DebugConfiguration , token ?: vscode . CancellationToken ) : vscode . ProviderResult < vscode . DebugConfiguration > {
37- if ( config && config . type == debuggerType ) {
38- let launchUri :string = '' ;
39- if ( folder . uri . scheme == 'file' ) {
40- const baseUrl :string = config . file || config . url ;
41- const replacedUri :string = baseUrl . replace ( '${workspaceFolder}' , folder . uri . path ) ;
42- launchUri = utils . pathToFileURL ( replacedUri ) ;
32+ if ( config && config . type == debuggerType ) {
33+ if ( config . request && config . request . localeCompare ( 'attach' , 'en' , { sensitivity : 'base' } ) == 0 ) {
34+ attach ( context ) ;
4335 } else {
44- launchUri = config . url ;
36+ let launchUri : string = '' ;
37+ if ( folder . uri . scheme == 'file' ) {
38+ const baseUrl : string = config . file || config . url ;
39+ const replacedUri : string = baseUrl . replace ( '${workspaceFolder}' , folder . uri . path ) ;
40+ launchUri = utils . pathToFileURL ( replacedUri ) ;
41+ } else {
42+ launchUri = config . url ;
43+ }
44+ launch ( context , launchUri , config . chromePath ) ;
4545 }
46- launch ( context , launchUri , config . chromePath ) ;
46+ } else {
47+ vscode . window . showErrorMessage ( 'No supported launch config was found.' ) ;
4748 }
4849 return ;
4950 }
5051 } ) ;
5152}
5253
53- async function launch ( context : vscode . ExtensionContext , launchUrl ?:string , chromePathFromLaunchConfig ?:string ) {
54+ async function launch ( context : vscode . ExtensionContext , launchUrl ?: string , chromePathFromLaunchConfig ?: string ) {
5455 const portFree = await utils . isPortFree ( hostname , port ) ;
5556
5657 if ( portFree ) {
5758 const pathToChrome = settings . get ( 'chromePath' ) as string || chromePathFromLaunchConfig || utils . getPathToChrome ( ) ;
5859
59- if ( ! pathToChrome || ! utils . existsSync ( pathToChrome ) ) {
60+ if ( ! pathToChrome || ! utils . existsSync ( pathToChrome ) ) {
6061 vscode . window . showErrorMessage ( 'Chrome was not found. Chrome must be installed for this extension to function. If you have Chrome installed at a custom location you can specify it in the \'chromePath\' setting.' ) ;
6162 return ;
6263 }
6364
64- utils . launchLocalChrome ( pathToChrome , port , 'about:blank' ) ;
65+ utils . launchLocalChrome ( pathToChrome , port , 'about:blank' ) ;
6566 }
66-
67- ///json/new?{url}
67+
6868 const target = JSON . parse ( await utils . getURL ( `http://${ hostname } :${ port } /json/new?${ launchUrl } ` ) ) ;
6969
70- if ( ! target || ! target . webSocketDebuggerUrl || target . webSocketDebuggerUrl == '' ) {
70+ if ( ! target || ! target . webSocketDebuggerUrl || target . webSocketDebuggerUrl == '' ) {
7171 vscode . window . showErrorMessage ( `Could not find the launched Chrome tab: (${ launchUrl } ).` ) ;
7272 attach ( context ) ;
7373 } else {
@@ -94,22 +94,13 @@ async function attach(context: vscode.ExtensionContext) {
9494 }
9595}
9696
97- async function getWebSocketUri ( targetUrl : string ) : Promise < string > {
98- const responseArray = await getListOfTargets ( ) ;
99-
100- // Always return the first match which is the logic in the Chrome debug extension too
101- const match = responseArray . find ( i => i . url . indexOf ( targetUrl ) !== - 1 ) ;
102-
103- return ( match && match . webSocketUri ) ? match . webSocketUri : '' ;
104- }
105-
10697async function getListOfTargets ( ) : Promise < Array < any > > {
10798 const checkDiscoveryEndpoint = ( url : string ) => {
10899 return utils . getURL ( url , { headers : { Host : 'localhost' } } ) ;
109100 } ;
110101
111102 const jsonResponse = await checkDiscoveryEndpoint ( `http://${ hostname } :${ port } /json/list` )
112- . catch ( ( ) => checkDiscoveryEndpoint ( `http://${ hostname } :${ port } /json` ) ) ;
103+ . catch ( ( ) => checkDiscoveryEndpoint ( `http://${ hostname } :${ port } /json` ) ) ;
113104
114105 return JSON . parse ( jsonResponse ) ;
115106}
@@ -228,7 +219,7 @@ class DevToolsPanel {
228219
229220 private _onOpen ( ) {
230221 this . _isConnected = true ;
231- // Tell the devtools that the real websocket was opened
222+ // Tell the devtools that the real websocket was opened
232223 this . _panel . webview . postMessage ( 'open' ) ;
233224
234225 if ( this . _socket ) {
0 commit comments