Skip to content

Commit ab03c68

Browse files
authored
chore: move network view behind a setting (#2059)
We don't want it to appear for everyone quite yet: move it behind an experimental setting. Swaps the controls around from the session enabling networking eagerly to being a call from the extension side to do so.
1 parent 34348f2 commit ab03c68

11 files changed

+104
-68
lines changed

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"configuration.resourceRequestOptions": "Request options to use when loading resources, such as source maps, in the debugger. You may need to configure this if your sourcemaps require authentication or use a self-signed certificate, for instance. Options are used to create a request using the [`got`](https://github.com/sindresorhus/got) library.\n\nA common case to disable certificate verification can be done by passing `{ \"https\": { \"rejectUnauthorized\": false } }`.",
7171
"configuration.terminalOptions": "Default launch options for the JavaScript debug terminal and npm scripts.",
7272
"configuration.unmapMissingSources": "Configures whether sourcemapped file where the original file can't be read will automatically be unmapped. If this is false (default), a prompt is shown.",
73+
"configuration.enableNetworkView": "Enables the experimental network view for targets that support it.",
7374
"createDiagnostics.label": "Diagnose Breakpoint Problems",
7475
"customDescriptionGenerator.description": "Customize the textual description the debugger shows for objects (local variables, etc...). Samples:\n 1. this.toString() // will call toString to print all objects\n 2. this.customDescription ? this.customDescription() : defaultValue // Use customDescription method if available, if not return defaultValue\n 3. function (def) { return this.customDescription ? this.customDescription() : def } // Use customDescription method if available, if not return defaultValue\n ",
7576
"customPropertiesGenerator.description": "Customize the properties shown for an object in the debugger (local variables, etc...). Samples:\n 1. { ...this, extraProperty: '12345' } // Add an extraProperty 12345 to all objects\n 2. this.customProperties ? this.customProperties() : this // Use customProperties method if available, if not use the properties in this (the default properties)\n 3. function () { return this.customProperties ? this.customProperties() : this } // Use customDescription method if available, if not return the default properties\n\n Deprecated: This is a temporary implementation of this feature until we have time to implement it in the way described here: https://github.com/microsoft/vscode/issues/102181",

src/adapter/debugAdapter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export class DebugAdapter implements IDisposable {
121121
this.dap.on('setDebuggerProperty', params => this._setDebuggerProperty(params));
122122
this.dap.on('setSymbolOptions', params => this._setSymbolOptions(params));
123123
this.dap.on('networkCall', params => this._doNetworkCall(params));
124+
this.dap.on('enableNetworking', params => this._withThread(t => t.enableNetworking(params)));
124125
}
125126

126127
private async _doNetworkCall({ method, params }: Dap.NetworkCallParams) {

src/adapter/threads.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { DebugType } from '../common/contributionUtils';
99
import { EventEmitter } from '../common/events';
1010
import { HrTime } from '../common/hrnow';
1111
import { ILogger, LogTag } from '../common/logging';
12-
import { mirroredNetworkEvents } from '../common/networkEvents';
1312
import { isInstanceOf, truthy } from '../common/objUtils';
1413
import { Base0Position, Base1Position, Range } from '../common/positions';
1514
import { IDeferred, delay, getDeferred } from '../common/promiseUtil';
@@ -741,26 +740,6 @@ export class Thread implements IVariableStoreLocationProvider {
741740
} else this._revealObject(event.object);
742741
});
743742

744-
if (!this.launchConfig.noDebug) {
745-
// Use whether we can make a cookies request to feature-request the
746-
// availability of networking.
747-
this._cdp.Network.enable({}).then(r => {
748-
if (!r) {
749-
return;
750-
}
751-
752-
this._dap.with(dap => {
753-
dap.networkAvailable({});
754-
for (const event of mirroredNetworkEvents) {
755-
// the types don't work well with the overloads on Network.on, a cast is needed:
756-
(this._cdp.Network.on as (ev: string, fn: (d: object) => void) => void)(event, data =>
757-
dap.networkEvent({ data, event }),
758-
);
759-
}
760-
});
761-
});
762-
}
763-
764743
this._cdp.Debugger.on('paused', async event => this._onPaused(event));
765744
this._cdp.Debugger.on('resumed', () => this.onResumed());
766745
this._cdp.Debugger.on('scriptParsed', event => this._onScriptParsed(event));
@@ -791,6 +770,29 @@ export class Thread implements IVariableStoreLocationProvider {
791770
this._dap.resolve();
792771
}
793772

773+
/**
774+
* Tries to enable networking for the target
775+
*/
776+
async enableNetworking({
777+
mirrorEvents,
778+
}: Dap.EnableNetworkingParams): Promise<Dap.EnableNetworkingResult> {
779+
const ok = await this._cdp.Network.enable({});
780+
if (!ok) {
781+
throw errors.networkingNotAvailable();
782+
}
783+
784+
this._dap.with(dap => {
785+
for (const event of mirrorEvents) {
786+
// the types don't work well with the overloads on Network.on, a cast is needed:
787+
(this._cdp.Network.on as (ev: string, fn: (d: object) => void) => void)(event, data =>
788+
dap.networkEvent({ data, event }),
789+
);
790+
}
791+
});
792+
793+
return {};
794+
}
795+
794796
/**
795797
* Implements DAP `stepInTargets` request.
796798
*

src/build/dapCustom.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -730,12 +730,6 @@ const dapCustom: JSONSchema4 = {
730730
'Arguments for "setSymbolOptions" request. Properties are determined by debugger.',
731731
},
732732

733-
...makeEvent(
734-
'networkAvailable',
735-
'Fired when we successfully enable CDP networking on the session.',
736-
{},
737-
),
738-
739733
...makeEvent(
740734
'networkEvent',
741735
'A wrapped CDP network event. There is little abstraction here because UI interacts literally with CDP at the moment.',
@@ -774,6 +768,24 @@ const dapCustom: JSONSchema4 = {
774768
type: 'object',
775769
},
776770
),
771+
772+
...makeRequest(
773+
'enableNetworking',
774+
'Attempts to enable networking on the target.',
775+
{
776+
properties: {
777+
mirrorEvents: {
778+
type: 'array',
779+
items: { type: 'string' },
780+
description: 'CDP network domain events to mirror (e.g. "requestWillBeSent")',
781+
},
782+
},
783+
required: ['mirrorEvents'],
784+
},
785+
{
786+
type: 'object',
787+
},
788+
),
777789
},
778790
};
779791

src/build/generate-contributions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,11 @@ const configurationSchema: ConfigurationAttributes<IConfigurationTypes> = {
12401240
default: {},
12411241
markdownDescription: refString('configuration.resourceRequestOptions'),
12421242
},
1243+
[Configuration.EnableNetworkView]: {
1244+
type: 'boolean',
1245+
default: false,
1246+
description: refString('configuration.enableNetworkView'),
1247+
},
12431248
};
12441249

12451250
const commands: ReadonlyArray<{

src/common/contributionUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export const enum Configuration {
172172
UnmapMissingSources = 'debug.javascript.unmapMissingSources',
173173
DefaultRuntimeExecutables = 'debug.javascript.defaultRuntimeExecutable',
174174
ResourceRequestOptions = 'debug.javascript.resourceRequestOptions',
175+
EnableNetworkView = 'debug.javascript.enableNetworkView',
175176
}
176177

177178
export type DebugByLinkState = 'on' | 'off' | 'always';
@@ -193,6 +194,7 @@ export interface IConfigurationTypes {
193194
[Configuration.UnmapMissingSources]: boolean;
194195
[Configuration.DefaultRuntimeExecutables]: { [K in DebugType]?: string };
195196
[Configuration.ResourceRequestOptions]: Partial<OptionsOfBufferResponseBody>;
197+
[Configuration.EnableNetworkView]: boolean;
196198
}
197199

198200
export interface IStackFrameContext {

src/dap/api.d.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,11 +1157,6 @@ export namespace Dap {
11571157
*/
11581158
setSymbolOptionsRequest(params: SetSymbolOptionsParams): Promise<SetSymbolOptionsResult>;
11591159

1160-
/**
1161-
* Fired when we successfully enable CDP networking on the session.
1162-
*/
1163-
networkAvailable(params: NetworkAvailableEventParams): void;
1164-
11651160
/**
11661161
* A wrapped CDP network event. There is little abstraction here because UI interacts literally with CDP at the moment.
11671162
*/
@@ -1178,6 +1173,18 @@ export namespace Dap {
11781173
* Makes a network call. There is little abstraction here because UI interacts literally with CDP at the moment.
11791174
*/
11801175
networkCallRequest(params: NetworkCallParams): Promise<NetworkCallResult>;
1176+
1177+
/**
1178+
* Attempts to enable networking on the target.
1179+
*/
1180+
on(
1181+
request: 'enableNetworking',
1182+
handler: (params: EnableNetworkingParams) => Promise<EnableNetworkingResult | Error>,
1183+
): () => void;
1184+
/**
1185+
* Attempts to enable networking on the target.
1186+
*/
1187+
enableNetworkingRequest(params: EnableNetworkingParams): Promise<EnableNetworkingResult>;
11811188
}
11821189

11831190
export interface TestApi {
@@ -1939,16 +1946,6 @@ export namespace Dap {
19391946
*/
19401947
setSymbolOptions(params: SetSymbolOptionsParams): Promise<SetSymbolOptionsResult>;
19411948

1942-
/**
1943-
* Fired when we successfully enable CDP networking on the session.
1944-
*/
1945-
on(request: 'networkAvailable', handler: (params: NetworkAvailableEventParams) => void): void;
1946-
off(request: 'networkAvailable', handler: (params: NetworkAvailableEventParams) => void): void;
1947-
once(
1948-
request: 'networkAvailable',
1949-
filter?: (event: NetworkAvailableEventParams) => boolean,
1950-
): Promise<NetworkAvailableEventParams>;
1951-
19521949
/**
19531950
* A wrapped CDP network event. There is little abstraction here because UI interacts literally with CDP at the moment.
19541951
*/
@@ -1963,6 +1960,11 @@ export namespace Dap {
19631960
* Makes a network call. There is little abstraction here because UI interacts literally with CDP at the moment.
19641961
*/
19651962
networkCall(params: NetworkCallParams): Promise<NetworkCallResult>;
1963+
1964+
/**
1965+
* Attempts to enable networking on the target.
1966+
*/
1967+
enableNetworking(params: EnableNetworkingParams): Promise<EnableNetworkingResult>;
19661968
}
19671969

19681970
export interface AttachParams {
@@ -2263,6 +2265,15 @@ export namespace Dap {
22632265

22642266
export interface DisconnectResult {}
22652267

2268+
export interface EnableNetworkingParams {
2269+
/**
2270+
* CDP network domain events to mirror (e.g. "requestWillBeSent")
2271+
*/
2272+
mirrorEvents: string[];
2273+
}
2274+
2275+
export interface EnableNetworkingResult {}
2276+
22662277
export interface EvaluateParams {
22672278
/**
22682279
* The expression to evaluate.
@@ -2946,8 +2957,6 @@ export namespace Dap {
29462957
totalModules?: integer;
29472958
}
29482959

2949-
export interface NetworkAvailableEventParams {}
2950-
29512960
export interface NetworkCallParams {
29522961
/**
29532962
* The HTTP method

src/dap/errors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ export const sourceMapParseFailed = (compiledUrl: string, message: string) =>
220220
export const uwpPipeNotAvailable = () =>
221221
createUserError(l10n.t('UWP webview debugging is not available on your platform.'));
222222

223+
export const networkingNotAvailable = () => createUserError(l10n.t('Networking not available.'));
224+
223225
export const noUwpPipeFound = () =>
224226
createUserError(
225227
l10n.t(

src/dap/telemetryClassification.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,6 @@ interface IDAPOperationClassification {
142142
'!setsymboloptions.errors': { classification: 'CallstackOrException'; purpose: 'PerformanceAndHealth' };
143143
networkcall: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth' };
144144
'!networkcall.errors': { classification: 'CallstackOrException'; purpose: 'PerformanceAndHealth' };
145+
enablenetworking: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth' };
146+
'!enablenetworking.errors': { classification: 'CallstackOrException'; purpose: 'PerformanceAndHealth' };
145147
}

src/ui/debugSessionTracker.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,9 @@ export class DebugSessionTracker implements vscode.Disposable {
4343

4444
private _onSessionAddedEmitter = new vscode.EventEmitter<vscode.DebugSession>();
4545
private _onSessionEndedEmitter = new vscode.EventEmitter<vscode.DebugSession>();
46-
private _onNetworkAvailabilityChangeEmitter = new vscode.EventEmitter<vscode.DebugSession>();
4746
private _disposables: vscode.Disposable[] = [];
48-
private readonly networkAvailable = new WeakSet<vscode.DebugSession>();
4947
private readonly sessions = new Map<string, vscode.DebugSession>();
5048

51-
/**
52-
* Fired when networking becomes available for a debug session.
53-
*/
54-
public onNetworkAvailabilityChanged = this._onNetworkAvailabilityChangeEmitter.event;
55-
5649
/**
5750
* Fires when any new js-debug session comes in.
5851
*/
@@ -77,13 +70,6 @@ export class DebugSessionTracker implements vscode.Disposable {
7770
return this.sessions.get(id);
7871
}
7972

80-
/**
81-
* Gets whether networkign is available in the session.
82-
*/
83-
public isNetworkAvailable(session: vscode.DebugSession) {
84-
return this.networkAvailable.has(session);
85-
}
86-
8773
/**
8874
* Gets whether the js-debug session is still running.
8975
*/
@@ -154,9 +140,6 @@ export class DebugSessionTracker implements vscode.Disposable {
154140
} else if (event.event === 'copyRequested') {
155141
const params = event.body as Dap.CopyRequestedEventParams;
156142
vscode.env.clipboard.writeText(params.text);
157-
} else if (event.event === 'networkAvailable') {
158-
this.networkAvailable.add(event.session);
159-
this._onNetworkAvailabilityChangeEmitter.fire(event.session);
160143
}
161144
},
162145
undefined,

0 commit comments

Comments
 (0)