Skip to content
This repository was archived by the owner on Sep 17, 2021. It is now read-only.

Commit 222152b

Browse files
committed
basic debugger launch cmd
1 parent d4484fd commit 222152b

File tree

3 files changed

+72
-54
lines changed

3 files changed

+72
-54
lines changed

package.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,31 @@
5252
"category": "DevTools for Chrome"
5353
}
5454
],
55+
"debuggers": [
56+
{
57+
"type": "devtools-for-chrome",
58+
"label": "DevTools for Chrome",
59+
"configurationAttributes": {
60+
"launch": {
61+
"required": [
62+
"url"
63+
],
64+
"properties": {
65+
"url": {
66+
"type": "string",
67+
"description": "Absolute uri to launch.",
68+
"default": "http://localhost:8080"
69+
},
70+
"chromePath": {
71+
"type": "string",
72+
"description": "Absolute path to the Chrome instance to launch.",
73+
"default": ""
74+
}
75+
}
76+
}
77+
}
78+
}
79+
],
5580
"configuration": {
5681
"title": "DevTools for Chrome",
5782
"type": "object",
@@ -99,4 +124,4 @@
99124
"tslint": "^5.11.0",
100125
"typescript": "^3.1.1"
101126
}
102-
}
127+
}

src/ChromeDevToolsConfigurationProvider.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/extension.ts

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import * as path from 'path';
22
import * as vscode from 'vscode';
3-
import {ChromeDevToolsConfigurationProvider} from './ChromeDevToolsConfigurationProvider'
43
import WebSocket from 'ws';
54
import QuickPickItem = vscode.QuickPickItem;
65
import * as utils from './utils';
6+
import { isRegExp } from 'util';
77

88
const settings = vscode.workspace.getConfiguration('vscode-devtools-for-chrome');
99
const hostname = settings.get('hostname') as string || 'localhost';
1010
const port = settings.get('port') as number || 9222;
11-
const debugConfigProvider:ChromeDevToolsConfigurationProvider = new ChromeDevToolsConfigurationProvider();
11+
const debuggerType = 'devtools-for-chrome';
12+
const DEFAULT_CONFIG = {
13+
type: debuggerType,
14+
name: 'Launch Chrome against localhost',
15+
url: 'http://localhost:8080',
16+
};
1217

1318
export function activate(context: vscode.ExtensionContext) {
1419
context.subscriptions.push(vscode.commands.registerCommand('devtools-for-chrome.launch', async () => {
@@ -20,28 +25,58 @@ export function activate(context: vscode.ExtensionContext) {
2025
}));
2126

2227
vscode.debug.onDidStartDebugSession( async (e: vscode.DebugSession) => {
23-
debugSessionStart(e, context);
28+
//debugSessionStart(e, context);
2429
});
2530

26-
vscode.debug.registerDebugConfigurationProvider('chrome', debugConfigProvider);
31+
vscode.debug.registerDebugConfigurationProvider(debuggerType, {
32+
provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration[]> {
33+
return;
34+
},
35+
36+
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);
43+
} else {
44+
launchUri = config.url;
45+
}
46+
launch(context, launchUri, config.chromePath);
47+
}
48+
return;
49+
}
50+
});
2751
}
2852

29-
async function launch(context: vscode.ExtensionContext) {
53+
async function launch(context: vscode.ExtensionContext, launchUrl?:string, chromePathFromLaunchConfig?:string) {
3054
const portFree = await utils.isPortFree(hostname, port);
55+
3156
if (portFree) {
32-
const pathToChrome = settings.get('chromePath') as string || utils.getPathToChrome();
33-
if (pathToChrome || utils.existsSync(pathToChrome) ) {
34-
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 speficy it in the \'chromePath\' setting.');
57+
const pathToChrome = settings.get('chromePath') as string || chromePathFromLaunchConfig || utils.getPathToChrome();
58+
59+
if (!pathToChrome || !utils.existsSync(pathToChrome) ) {
60+
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.');
3561
return;
3662
}
37-
utils.launchLocalChrome(pathToChrome, port, 'about:blank');
63+
64+
utils.launchLocalChrome(pathToChrome, port, 'about:blank' );
3865
}
66+
67+
///json/new?{url}
68+
const target = JSON.parse(await utils.getURL(`http://${hostname}:${port}/json/new?${launchUrl}`));
3969

40-
attach(context);
70+
if(!target || !target.webSocketDebuggerUrl || target.webSocketDebuggerUrl == ''){
71+
vscode.window.showErrorMessage(`Could not find the launched Chrome tab: (${launchUrl}).`);
72+
attach(context);
73+
} else {
74+
DevToolsPanel.createOrShow(context.extensionPath, target.webSocketDebuggerUrl);
75+
}
4176
}
4277

4378
async function attach(context: vscode.ExtensionContext) {
44-
const responseArray = getListOfTargets();
79+
const responseArray = await getListOfTargets();
4580

4681
if (Array.isArray(responseArray)) {
4782
const items: QuickPickItem[] = [];
@@ -59,20 +94,6 @@ async function attach(context: vscode.ExtensionContext) {
5994
}
6095
}
6196

62-
async function debugSessionStart(e: vscode.DebugSession, context: vscode.ExtensionContext) {
63-
if(e.type == 'chrome') {
64-
debugger;
65-
console.log(arguments);
66-
let targetUrl = debugConfigProvider.TargetUri;
67-
let webSocketUri:string = await getWebSocketUri(targetUrl);
68-
if(!webSocketUri || webSocketUri == ''){
69-
vscode.window.showErrorMessage(`Could not find the launched Chrome tab: (${targetUrl}).`);
70-
} else {
71-
DevToolsPanel.createOrShow(context.extensionPath, webSocketUri);
72-
}
73-
}
74-
}
75-
7697
async function getWebSocketUri(targetUrl: string): Promise<string> {
7798
const responseArray = await getListOfTargets();
7899

0 commit comments

Comments
 (0)