Skip to content
This repository was archived by the owner on Dec 6, 2022. It is now read-only.

Commit 5908efd

Browse files
authored
Merge pull request #727 from stristr/master
Use nullable `targetTypes` property for advanced debugging.
2 parents 63aa127 + 4c59042 commit 5908efd

10 files changed

Lines changed: 52 additions & 9 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ See our wiki page for some configured example apps: [Examples](https://github.co
133133
* `userDataDir`: Normally, if Chrome is already running when you start debugging with a launch config, then the new instance won't start in remote debugging mode. So by default, the extension launches Chrome with a separate user profile in a temp folder. Use this option to set a different path to use, or set to false to launch with your default user profile.
134134
* `url`: On a 'launch' config, it will launch Chrome at this URL.
135135
* `urlFilter`: On an 'attach' config, or a 'launch' config with no 'url' set, search for a page with this url and attach to it. It can also contain wildcards, for example, `"localhost:*/app"` will match either `"http://localhost:123/app"` or `"http://localhost:456/app"`, but not `"https://stackoverflow.com"`.
136+
* `targetTypes`: On an 'attach' config, or a 'launch' config with no 'url' set, set a list of acceptable target types from the default `["page"]`. For example, if you are attaching to an Electron app, you might want to set this to `["page", "webview"]`. A value of `null` disables filtering by target type.
136137
* `sourceMaps`: By default, the adapter will use sourcemaps and your original sources whenever possible. You can disable this by setting `sourceMaps` to false.
137138
* `pathMapping`: This property takes a mapping of URL paths to local paths, to give you more flexibility in how URLs are resolved to local files. `"webRoot": "${workspaceFolder}"` is just shorthand for a pathMapping like `{ "/": "${workspaceFolder}" }`.
138139
* `smartStep`: Automatically steps over code that doesn't map to source files. Especially useful for debugging with async/await.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@
381381
"description": "%chrome.urlFilter.description%",
382382
"default": ""
383383
},
384+
"targetTypes": {
385+
"type": ["array", "null"],
386+
"description": "%chrome.targetTypes.description%",
387+
"default": ["page"]
388+
},
384389
"showAsyncStacks": {
385390
"type": "boolean",
386391
"description": "%chrome.showAsyncStacks.description%",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"chrome.timeout.description": "Retry for this number of milliseconds to connect to Chrome. Default is 10000 ms.",
2626
"chrome.disableNetworkCache.description": "Controls whether to skip the network cache for each request",
2727
"chrome.urlFilter.description": "Will search for a page with this url and attach to it, if found. Can have * wildcards.",
28+
"chrome.targetTypes.description": "An array of acceptable target types. The default is `[\"page\"]`.",
2829
"chrome.showAsyncStacks.description": "Show the async calls that led to the current call stack",
2930
"chrome.breakOnLoad.description": "Experimental feature - If true, the debug adapter will attempt to set breakpoints in scripts before they are loaded, so it can hit breakpoints at the beginnings of those scripts. Has a perf impact.",
3031
"chrome.breakOnLoadStrategy.description": "The strategy to use for breakOnLoad.",

src/chromeDebug.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { ChromeDebugSession, logger, UrlPathTransformer, BaseSourceMapTransformer, telemetry } from 'vscode-chrome-debug-core';
66
import * as path from 'path';
77
import * as os from 'os';
8-
import { targetFilter } from './utils';
8+
import { defaultTargetFilter } from './utils';
99

1010
import { ChromeDebugAdapter } from './chromeDebugAdapter';
1111

@@ -18,7 +18,7 @@ ChromeDebugSession.run(ChromeDebugSession.getSession(
1818
adapter: ChromeDebugAdapter,
1919
extensionName: EXTENSION_NAME,
2020
logFilePath: path.resolve(os.tmpdir(), 'vscode-chrome-debug.txt'),
21-
targetFilter,
21+
targetFilter: defaultTargetFilter,
2222

2323
pathTransformer: UrlPathTransformer,
2424
sourceMapTransformer: BaseSourceMapTransformer,

src/chromeDebugAdapter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
206206
args.sourceMapPathOverrides = getSourceMapPathOverrides(args.webRoot, args.sourceMapPathOverrides);
207207
args.skipFileRegExps = ['^chrome-extension:.*'];
208208

209+
if (args.targetTypes === undefined) {
210+
args.targetFilter = utils.defaultTargetFilter;
211+
} else {
212+
args.targetFilter = utils.getTargetFilter(args.targetTypes);
213+
}
214+
209215
super.commonArgs(args);
210216
}
211217

src/chromeDebugInterfaces.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { DebugProtocol } from 'vscode-debugprotocol';
88
export interface ICommonRequestArgs extends Core.ICommonRequestArgs {
99
webRoot?: string;
1010
disableNetworkCache?: boolean;
11+
targetTypes?: string[];
12+
targetFilter?: Core.chromeConnection.ITargetFilter;
1113
urlFilter?: string;
1214
}
1315

src/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
import * as vscode from 'vscode';
66
import * as Core from 'vscode-chrome-debug-core';
7+
import * as nls from 'vscode-nls';
78

8-
import { targetFilter } from './utils';
9+
import { defaultTargetFilter } from './utils';
910

10-
import * as nls from 'vscode-nls';
1111
const localize = nls.loadMessageBundle();
1212

1313
export function activate(context: vscode.ExtensionContext) {
@@ -50,7 +50,7 @@ export class ChromeConfigurationProvider implements vscode.DebugConfigurationPro
5050

5151
let targets;
5252
try {
53-
targets = await discovery.getAllTargets(config.address || '127.0.0.1', config.port, targetFilter, config.url || config.urlFilter);
53+
targets = await discovery.getAllTargets(config.address || '127.0.0.1', config.port, defaultTargetFilter, config.url || config.urlFilter);
5454
} catch (e) {
5555
// Target not running?
5656
}

src/utils.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*--------------------------------------------------------*/
44

55
import * as path from 'path';
6-
import {utils as coreUtils, chromeConnection } from 'vscode-chrome-debug-core';
6+
import { utils as coreUtils, chromeConnection } from 'vscode-chrome-debug-core';
77

88
const WIN_APPDATA = process.env.LOCALAPPDATA || '/';
99
const DEFAULT_CHROME_PATH = {
@@ -64,5 +64,12 @@ export class DebounceHelper {
6464
}
6565
}
6666

67-
export const targetFilter: chromeConnection.ITargetFilter =
68-
target => target && (!target.type || target.type === 'page');
67+
export const getTargetFilter = (targetTypes?: string[]): chromeConnection.ITargetFilter => {
68+
if (targetTypes) {
69+
return target => target && (!target.type || targetTypes.indexOf(target.type) !== -1);
70+
}
71+
72+
return () => true;
73+
};
74+
75+
export const defaultTargetFilter = getTargetFilter(['page']);

test/chromeDebugAdapter.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ suite('ChromeDebugAdapter', () => {
4646
.setup(x => x.sendRequest(It.isAnyString(), It.isAny(), It.isAnyNumber(), It.isAny()))
4747
.verifiable(Times.atLeast(0));
4848

49+
mockChromeConnection
50+
.setup(x => x.setTargetFilter(It.isAny()))
51+
.verifiable(Times.atLeast(0));
4952
mockChromeConnection
5053
.setup(x => x.api)
5154
.returns(() => mockChrome.apiObjects)

test/utils.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,22 @@ suite('Utils', () => {
7979
'/usr/bin/google-chrome');
8080
});
8181
});
82-
});
82+
83+
suite('getTargetFilter()', () => {
84+
test('defaultTargetFilter', () => {
85+
const {defaultTargetFilter} = getUtils();
86+
const targets = [{type: 'page'}, {type: 'webview'}];
87+
assert.deepEqual(targets.filter(defaultTargetFilter), [{type: 'page'}]);
88+
});
89+
90+
test('getTargetFilter', () => {
91+
const {getTargetFilter} = getUtils();
92+
const targets = [{type: 'page'}, {type: 'webview'}];
93+
assert.deepEqual(targets.filter(getTargetFilter(['page'])), [{type: 'page'}]);
94+
assert.deepEqual(targets.filter(getTargetFilter(['webview'])), [{type: 'webview'}]);
95+
assert.deepEqual(targets.filter(getTargetFilter(['page', 'webview'])), targets);
96+
// Falsy targetTypes should effectively disable filtering.
97+
assert.deepEqual(targets.filter(getTargetFilter()), targets);
98+
});
99+
});
100+
});

0 commit comments

Comments
 (0)