Skip to content

Commit 0ced734

Browse files
committed
feat: add Edge inspector integration
1 parent 788729e commit 0ced734

File tree

9 files changed

+114
-20
lines changed

9 files changed

+114
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This changelog records changes to stable releases since 1.50.2. "TBA" changes he
66

77
- feat: support renamed sourcemap identifiers ([ref](https://github.com/microsoft/vscode/issues/12066))
88
- feat: support DAP `hitBreakpointIds` ([#994](https://github.com/microsoft/vscode-js-debug/issues/994))
9+
- feat: add Edge inspector integration
910
- refactor: include a mandator path in the CDP proxy ([#987](https://github.com/microsoft/vscode-js-debug/issues/987))
1011
- fix: make sure servers are listening before returning
1112
- fix: don't send infinite telemetry requests for React Native ([#981](https://github.com/microsoft/vscode-js-debug/issues/981))

src/build/generate-contributions.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,11 @@ const commands: ReadonlyArray<{
12491249
title: refString('startWithStopOnEntry.label'),
12501250
category: 'Debug',
12511251
},
1252+
{
1253+
command: Commands.OpenEdgeDevTools,
1254+
title: refString('openEdgeDevTools.label'),
1255+
icon: '$(inspect)',
1256+
},
12521257
];
12531258

12541259
const menus: Menus = {
@@ -1282,6 +1287,11 @@ const menus: Menus = {
12821287
title: refString('createDiagnostics.label'),
12831288
when: forAnyDebugType('debugType', 'inDebugMode'),
12841289
},
1290+
{
1291+
command: Commands.OpenEdgeDevTools,
1292+
title: refString('openEdgeDevTools.label'),
1293+
when: `debugType == ${DebugType.Edge}`,
1294+
},
12851295
],
12861296
'debug/callstack/context': [
12871297
{
@@ -1320,6 +1330,10 @@ const menus: Menus = {
13201330
command: Commands.StopProfile,
13211331
when: forAnyDebugType('debugType', 'jsDebugIsProfiling'),
13221332
},
1333+
{
1334+
command: Commands.OpenEdgeDevTools,
1335+
when: `debugType == ${DebugType.Edge}`,
1336+
},
13231337
],
13241338
'view/title': [
13251339
{

src/build/strings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ A common case to disable certificate verification can be done by passing \`{ "ht
309309
'createDiagnostics.label': 'Diagnose Breakpoint Problems',
310310
'startWithStopOnEntry.label': 'Start Debugging and Stop on Entry',
311311
'requestCDPProxy.label': 'Request CDP Proxy for Debug Session',
312+
'openEdgeDevTools.label': 'Open Browser Devtools',
312313
'workspaceTrust.description': 'Trust is required to debug code in this workspace.',
313314
};
314315

src/common/contributionUtils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const enum Commands {
3838
StartProfile = 'extension.js-debug.startProfile',
3939
StopProfile = 'extension.js-debug.stopProfile',
4040
ToggleSkipping = 'extension.js-debug.toggleSkippingFile',
41+
OpenEdgeDevTools = 'extension.js-debug.openEdgeDevTools',
4142
}
4243

4344
export const enum DebugType {
@@ -77,6 +78,7 @@ const commandsObj: { [K in Commands]: null } = {
7778
[Commands.ToggleSkipping]: null,
7879
[Commands.StartWithStopOnEntry]: null,
7980
[Commands.RequestCDPProxy]: null,
81+
[Commands.OpenEdgeDevTools]: null,
8082
};
8183

8284
/**
@@ -165,6 +167,7 @@ export interface ICommandTypes {
165167
[Commands.RequestCDPProxy](
166168
sessionId: string,
167169
): { address: string; port: number; family: string } | null;
170+
[Commands.OpenEdgeDevTools](): void;
168171
}
169172

170173
/**

src/targets/browser/browserTargets.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ export class BrowserTarget implements ITarget, IThreadDelegate {
7979
/**
8080
* @inheritdoc
8181
*/
82-
public readonly supplementalConfig = {
83-
__usePerformanceFromParent:
84-
this._targetInfo.type !== BrowserTargetType.Page &&
85-
this._targetInfo.type !== BrowserTargetType.Page,
86-
};
82+
public get supplementalConfig() {
83+
const type = this.type();
84+
return {
85+
__browserTargetType: type,
86+
__usePerformanceFromParent: type !== BrowserTargetType.Page,
87+
};
88+
}
8789

8890
_children: Map<Cdp.Target.TargetID, BrowserTarget> = new Map();
8991

src/ui/debugSessionTracker.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@ export class DebugSessionTracker implements vscode.Disposable {
2020
return !!session.configuration.__pendingTargetId;
2121
}
2222

23+
/**
24+
* Prompts the user to pick one of the given debug sessions. Will not show
25+
* a prompt if candidates < 2.
26+
*/
27+
public static pickSession(candidates: vscode.DebugSession[], title: string) {
28+
if (candidates.length < 2) {
29+
return candidates[0];
30+
}
31+
32+
const qp = vscode.window.createQuickPick<{ id: string; label: string }>();
33+
qp.title = title;
34+
qp.items = candidates.map(c => ({ label: c.name, id: c.id }));
35+
qp.ignoreFocusOut = true;
36+
37+
return new Promise<vscode.DebugSession | undefined>(resolve => {
38+
qp.onDidAccept(() => resolve(candidates.find(i => i.id === qp.selectedItems[0]?.id)));
39+
qp.onDidHide(() => resolve(undefined));
40+
qp.show();
41+
}).finally(() => qp.dispose());
42+
}
43+
2344
private _onSessionAddedEmitter = new vscode.EventEmitter<vscode.DebugSession>();
2445
private _onSessionEndedEmitter = new vscode.EventEmitter<vscode.DebugSession>();
2546
private _disposables: vscode.Disposable[] = [];

src/ui/diagnosticsUI.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,10 @@ export class DiagnosticsUI implements IExtensionContribution {
8787
}
8888

8989
private pickSession() {
90-
const candidates = this.tracker.getConcreteSessions();
91-
if (candidates.length < 2) {
92-
return candidates[0];
93-
}
94-
95-
const qp = vscode.window.createQuickPick<{ id: string; label: string }>();
96-
qp.title = localize('selectInspectSession', 'Select the session you want to inspect:');
97-
qp.items = candidates.map(c => ({ label: c.name, id: c.id }));
98-
qp.ignoreFocusOut = true;
99-
100-
return new Promise<vscode.DebugSession | undefined>(resolve => {
101-
qp.onDidAccept(() => resolve(candidates.find(i => i.id === qp.selectedItems[0]?.id)));
102-
qp.onDidHide(() => resolve(undefined));
103-
qp.show();
104-
}).finally(() => qp.dispose());
90+
return DebugSessionTracker.pickSession(
91+
this.tracker.getConcreteSessions(),
92+
localize('selectInspectSession', 'Select the session you want to inspect:'),
93+
);
10594
}
10695

10796
private async getDiagnosticInfo(

src/ui/edgeDevToolOpener.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*---------------------------------------------------------
2+
* Copyright (C) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------*/
4+
5+
import { inject, injectable } from 'inversify';
6+
import * as vscode from 'vscode';
7+
import * as nls from 'vscode-nls';
8+
import { Commands, DebugType, registerCommand } from '../common/contributionUtils';
9+
import { IExtensionContribution } from '../ioc-extras';
10+
import { BrowserTargetType } from '../targets/browser/browserTargets';
11+
import { DebugSessionTracker } from './debugSessionTracker';
12+
13+
const localize = nls.loadMessageBundle();
14+
15+
const qualifies = (session: vscode.DebugSession) => {
16+
if (session?.type !== DebugType.Edge) {
17+
return false;
18+
}
19+
20+
const type: BrowserTargetType = session.configuration.__browserTargetType;
21+
return type === BrowserTargetType.IFrame || type === BrowserTargetType.Page;
22+
};
23+
24+
const toolExtensionId = 'ms-edgedevtools.vscode-edge-devtools';
25+
const commandId = 'vscode-edge-devtools.attachToCurrentDebugTarget';
26+
27+
@injectable()
28+
export class EdgeDevToolOpener implements IExtensionContribution {
29+
constructor(@inject(DebugSessionTracker) private readonly tracker: DebugSessionTracker) {}
30+
31+
/** @inheritdoc */
32+
public register(context: vscode.ExtensionContext) {
33+
context.subscriptions.push(
34+
registerCommand(vscode.commands, Commands.OpenEdgeDevTools, async () => {
35+
if (!vscode.extensions.all.some(e => e.id === toolExtensionId)) {
36+
return vscode.commands.executeCommand(
37+
'workbench.extensions.action.showExtensionsWithIds',
38+
[toolExtensionId],
39+
);
40+
}
41+
42+
const session =
43+
vscode.debug.activeDebugSession && qualifies(vscode.debug.activeDebugSession)
44+
? vscode.debug.activeDebugSession
45+
: await DebugSessionTracker.pickSession(
46+
this.tracker.getConcreteSessions().filter(qualifies),
47+
localize(
48+
'selectEdgeToolSession',
49+
'Select the page where you want to open the devtools',
50+
),
51+
);
52+
53+
if (!session) {
54+
return;
55+
}
56+
57+
return vscode.commands.executeCommand(commandId, session.id);
58+
}),
59+
);
60+
}
61+
}

src/ui/ui-ioc.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { DebugLinkUi } from './debugLinkUI';
1515
import { DebugSessionTracker } from './debugSessionTracker';
1616
import { DiagnosticsUI } from './diagnosticsUI';
1717
import { DisableSourceMapUI } from './disableSourceMapUI';
18+
import { EdgeDevToolOpener } from './edgeDevToolOpener';
1819
import { ILinkedBreakpointLocation } from './linkedBreakpointLocation';
1920
import { LinkedBreakpointLocationUI } from './linkedBreakpointLocationUI';
2021
import { LongPredictionUI } from './longPredictionUI';
@@ -47,6 +48,7 @@ export const registerUiComponents = (container: Container) => {
4748
container.bind(IExtensionContribution).to(DiagnosticsUI).inSingletonScope();
4849
container.bind(IExtensionContribution).to(StartDebugingAndStopOnEntry).inSingletonScope();
4950
container.bind(IExtensionContribution).to(JsDebugPortAttributesProvider).inSingletonScope();
51+
container.bind(IExtensionContribution).to(EdgeDevToolOpener).inSingletonScope();
5052
container.bind(ILinkedBreakpointLocation).to(LinkedBreakpointLocationUI).inSingletonScope();
5153
container.bind(DebugSessionTracker).toSelf().inSingletonScope().onActivation(trackDispose);
5254
container.bind(UiProfileManager).toSelf().inSingletonScope().onActivation(trackDispose);

0 commit comments

Comments
 (0)