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

Use nullable targetTypes property for advanced debugging. #727

Merged
merged 1 commit into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ See our wiki page for some configured example apps: [Examples](https://github.co
* `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.
* `url`: On a 'launch' config, it will launch Chrome at this URL.
* `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"`.
* `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.
* `sourceMaps`: By default, the adapter will use sourcemaps and your original sources whenever possible. You can disable this by setting `sourceMaps` to false.
* `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}" }`.
* `smartStep`: Automatically steps over code that doesn't map to source files. Especially useful for debugging with async/await.
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@
"description": "%chrome.urlFilter.description%",
"default": ""
},
"targetTypes": {
"type": ["array", "null"],
"description": "%chrome.targetTypes.description%",
"default": ["page"]
},
"showAsyncStacks": {
"type": "boolean",
"description": "%chrome.showAsyncStacks.description%",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"chrome.timeout.description": "Retry for this number of milliseconds to connect to Chrome. Default is 10000 ms.",
"chrome.disableNetworkCache.description": "Controls whether to skip the network cache for each request",
"chrome.urlFilter.description": "Will search for a page with this url and attach to it, if found. Can have * wildcards.",
"chrome.targetTypes.description": "An array of acceptable target types. The default is `[\"page\"]`.",
"chrome.showAsyncStacks.description": "Show the async calls that led to the current call stack",
"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.",
"chrome.breakOnLoadStrategy.description": "The strategy to use for breakOnLoad.",
Expand Down
4 changes: 2 additions & 2 deletions src/chromeDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { ChromeDebugSession, logger, UrlPathTransformer, BaseSourceMapTransformer, telemetry } from 'vscode-chrome-debug-core';
import * as path from 'path';
import * as os from 'os';
import { targetFilter } from './utils';
import { defaultTargetFilter } from './utils';

import { ChromeDebugAdapter } from './chromeDebugAdapter';

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

pathTransformer: UrlPathTransformer,
sourceMapTransformer: BaseSourceMapTransformer,
Expand Down
6 changes: 6 additions & 0 deletions src/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
args.sourceMapPathOverrides = getSourceMapPathOverrides(args.webRoot, args.sourceMapPathOverrides);
args.skipFileRegExps = ['^chrome-extension:.*'];

if (args.targetTypes === undefined) {
args.targetFilter = utils.defaultTargetFilter;
} else {
args.targetFilter = utils.getTargetFilter(args.targetTypes);
}

super.commonArgs(args);
}

Expand Down
2 changes: 2 additions & 0 deletions src/chromeDebugInterfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { DebugProtocol } from 'vscode-debugprotocol';
export interface ICommonRequestArgs extends Core.ICommonRequestArgs {
webRoot?: string;
disableNetworkCache?: boolean;
targetTypes?: string[];
targetFilter?: Core.chromeConnection.ITargetFilter;
urlFilter?: string;
}

Expand Down
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import * as vscode from 'vscode';
import * as Core from 'vscode-chrome-debug-core';
import * as nls from 'vscode-nls';

import { targetFilter } from './utils';
import { defaultTargetFilter } from './utils';

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

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

let targets;
try {
targets = await discovery.getAllTargets(config.address || '127.0.0.1', config.port, targetFilter, config.url || config.urlFilter);
targets = await discovery.getAllTargets(config.address || '127.0.0.1', config.port, defaultTargetFilter, config.url || config.urlFilter);
} catch (e) {
// Target not running?
}
Expand Down
13 changes: 10 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*--------------------------------------------------------*/

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

const WIN_APPDATA = process.env.LOCALAPPDATA || '/';
const DEFAULT_CHROME_PATH = {
Expand Down Expand Up @@ -64,5 +64,12 @@ export class DebounceHelper {
}
}

export const targetFilter: chromeConnection.ITargetFilter =
target => target && (!target.type || target.type === 'page');
export const getTargetFilter = (targetTypes?: string[]): chromeConnection.ITargetFilter => {
if (targetTypes) {
return target => target && (!target.type || targetTypes.indexOf(target.type) !== -1);
}

return () => true;
};

export const defaultTargetFilter = getTargetFilter(['page']);
3 changes: 3 additions & 0 deletions test/chromeDebugAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ suite('ChromeDebugAdapter', () => {
.setup(x => x.sendRequest(It.isAnyString(), It.isAny(), It.isAnyNumber(), It.isAny()))
.verifiable(Times.atLeast(0));

mockChromeConnection
.setup(x => x.setTargetFilter(It.isAny()))
.verifiable(Times.atLeast(0));
mockChromeConnection
.setup(x => x.api)
.returns(() => mockChrome.apiObjects)
Expand Down
20 changes: 19 additions & 1 deletion test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,22 @@ suite('Utils', () => {
'/usr/bin/google-chrome');
});
});
});

suite('getTargetFilter()', () => {
test('defaultTargetFilter', () => {
const {defaultTargetFilter} = getUtils();
const targets = [{type: 'page'}, {type: 'webview'}];
assert.deepEqual(targets.filter(defaultTargetFilter), [{type: 'page'}]);
});

test('getTargetFilter', () => {
const {getTargetFilter} = getUtils();
const targets = [{type: 'page'}, {type: 'webview'}];
assert.deepEqual(targets.filter(getTargetFilter(['page'])), [{type: 'page'}]);
assert.deepEqual(targets.filter(getTargetFilter(['webview'])), [{type: 'webview'}]);
assert.deepEqual(targets.filter(getTargetFilter(['page', 'webview'])), targets);
// Falsy targetTypes should effectively disable filtering.
assert.deepEqual(targets.filter(getTargetFilter()), targets);
});
});
});