Skip to content
This repository was archived by the owner on Jul 28, 2023. It is now read-only.

Commit 8b045f6

Browse files
committed
Add network tab
1 parent 5a1b0e5 commit 8b045f6

File tree

4 files changed

+125
-31
lines changed

4 files changed

+125
-31
lines changed

front_end/ndb.json

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
{
2-
"modules" : [
3-
{ "name": "ndb_sdk", "type": "autostart" },
4-
{ "name": "ndb", "type": "autostart" },
5-
{ "name": "layer_viewer" },
6-
{ "name": "timeline_model" },
7-
{ "name": "timeline" },
8-
{ "name": "product_registry" },
9-
{ "name": "mobile_throttling" },
10-
{ "name": "ndb_ui" },
11-
{ "name": "xterm" }
12-
],
2+
"modules": [
3+
{ "name": "ndb_sdk", "type": "autostart" },
4+
{ "name": "ndb", "type": "autostart" },
5+
{ "name": "layer_viewer" },
6+
{ "name": "timeline_model" },
7+
{ "name": "timeline" },
8+
{ "name": "product_registry" },
9+
{ "name": "mobile_throttling" },
10+
{ "name": "ndb_ui" },
11+
{ "name": "xterm" },
12+
{ "name": "emulation", "type": "autostart" },
13+
{ "name": "inspector_main", "type": "autostart" },
14+
{ "name": "mobile_throttling", "type": "autostart" },
15+
{ "name": "cookie_table" },
16+
{ "name": "har_importer" },
17+
{ "name": "network" }
18+
],
1319
"extends": "shell",
1420
"has_html": true
1521
}

front_end/ndb/NdbMain.js

+79-17
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@
55
*/
66

77
Ndb.nodeExecPath = function() {
8-
if (!Ndb._nodeExecPathPromise)
9-
Ndb._nodeExecPathPromise = Ndb.backend.which('node').then(result => result.resolvedPath);
8+
if (!Ndb._nodeExecPathPromise) {
9+
Ndb._nodeExecPathPromise = Ndb.backend
10+
.which('node')
11+
.then(result => result.resolvedPath);
12+
}
1013
return Ndb._nodeExecPathPromise;
1114
};
1215

1316
Ndb.npmExecPath = function() {
14-
if (!Ndb._npmExecPathPromise)
15-
Ndb._npmExecPathPromise = Ndb.backend.which('npm').then(result => result.resolvedPath);
17+
if (!Ndb._npmExecPathPromise) {
18+
Ndb._npmExecPathPromise = Ndb.backend
19+
.which('npm')
20+
.then(result => result.resolvedPath);
21+
}
1622
return Ndb._npmExecPathPromise;
1723
};
1824

@@ -27,39 +33,60 @@ Ndb.processInfo = function() {
2733
*/
2834
Ndb.NdbMain = class extends Common.Object {
2935
/**
30-
* @override
31-
*/
36+
* @override
37+
*/
3238
async run() {
3339
InspectorFrontendAPI.setUseSoftMenu(true);
3440
document.title = 'ndb';
35-
Common.moduleSetting('blackboxInternalScripts').addChangeListener(Ndb.NdbMain._calculateBlackboxState);
41+
Common.moduleSetting('blackboxInternalScripts').addChangeListener(
42+
Ndb.NdbMain._calculateBlackboxState
43+
);
3644
Ndb.NdbMain._calculateBlackboxState();
3745

3846
const setting = Persistence.isolatedFileSystemManager.workspaceFolderExcludePatternSetting();
3947
setting.set(Ndb.NdbMain._defaultExcludePattern().join('|'));
40-
Ndb.nodeProcessManager = await Ndb.NodeProcessManager.create(SDK.targetManager);
48+
Ndb.nodeProcessManager = await Ndb.NodeProcessManager.create(
49+
SDK.targetManager
50+
);
4151

42-
const {cwd} = await Ndb.processInfo();
52+
const { cwd } = await Ndb.processInfo();
4353
await Ndb.nodeProcessManager.addFileSystem(cwd);
4454

4555
// TODO(ak239): we do not want to create this model for workers, so we need a way to add custom capabilities.
46-
SDK.SDKModel.register(NdbSdk.NodeWorkerModel, SDK.Target.Capability.JS, true);
47-
SDK.SDKModel.register(NdbSdk.NodeRuntimeModel, SDK.Target.Capability.JS, true);
56+
SDK.SDKModel.register(
57+
NdbSdk.NodeWorkerModel,
58+
SDK.Target.Capability.JS,
59+
true
60+
);
61+
SDK.SDKModel.register(
62+
NdbSdk.NodeRuntimeModel,
63+
SDK.Target.Capability.JS,
64+
true
65+
);
4866

4967
await new Promise(resolve => SDK.initMainConnection(resolve));
50-
SDK.targetManager.createTarget('<root>', ls`Root`, SDK.Target.Type.Browser, null);
68+
SDK.targetManager.createTarget(
69+
'<root>',
70+
ls`Root`,
71+
SDK.Target.Type.Browser,
72+
null
73+
);
74+
5175
if (Common.moduleSetting('autoStartMain').get()) {
5276
const main = await Ndb.mainConfiguration();
5377
if (main) {
54-
if (main.prof)
55-
await Ndb.nodeProcessManager.profile(main.execPath, main.args);
56-
else
57-
Ndb.nodeProcessManager.debug(main.execPath, main.args);
78+
if (main.prof) {
79+
await Ndb.nodeProcessManager.profile(
80+
main.execPath,
81+
main.args
82+
);
83+
} else {Ndb.nodeProcessManager.debug(main.execPath, main.args);}
5884
}
5985
}
6086
Ndb.nodeProcessManager.startRepl();
6187
}
6288

89+
6390
static _defaultExcludePattern() {
6491
const defaultCommonExcludedFolders = [
6592
'/bower_components/', '/\\.devtools', '/\\.git/', '/\\.sass-cache/', '/\\.hg/', '/\\.idea/',
@@ -125,7 +152,6 @@ Ndb.mainConfiguration = async() => {
125152
prof
126153
};
127154
};
128-
129155
/**
130156
* @implements {UI.ContextMenu.Provider}
131157
* @unrestricted
@@ -172,9 +198,21 @@ Ndb.NodeProcessManager = class extends Common.Object {
172198
static async create(targetManager) {
173199
const manager = new Ndb.NodeProcessManager(targetManager);
174200
manager._service = await Ndb.backend.createService('ndd_service.js', rpc.handle(manager));
201+
InspectorFrontendHost.sendMessageToBackend = manager.sendMessageToBackend.bind(manager);
202+
175203
return manager;
176204
}
177205

206+
/**
207+
* @param {object} message
208+
*
209+
* @return {Promise} void
210+
*/
211+
async sendMessageToBackend(message) {
212+
if (this._service && this._service.sendMessage)
213+
return this._service.sendMessage(message);
214+
}
215+
178216
env() {
179217
return this._service.env();
180218
}
@@ -246,6 +284,30 @@ Ndb.NodeProcessManager = class extends Common.Object {
246284
}
247285
}
248286

287+
sendLoadingFinished({ type, payload }) {
288+
SDK._mainConnection._onMessage(JSON.stringify({
289+
method: 'Network.loadingFinished',
290+
params: payload
291+
}));
292+
}
293+
294+
responseToFrontEnd(id, result) {
295+
InspectorFrontendHost.events.dispatchEventToListeners(
296+
InspectorFrontendHostAPI.Events.DispatchMessage,
297+
{
298+
id,
299+
result
300+
}
301+
);
302+
}
303+
304+
sendNetworkData({ type, payload }) {
305+
SDK._mainConnection._onMessage(JSON.stringify({
306+
method: type,
307+
params: payload
308+
}));
309+
}
310+
249311
async terminalData(stream, data) {
250312
const content = await(await fetch(`data:application/octet-stream;base64,${data}`)).text();
251313
if (content.startsWith('Debugger listening on') || content.startsWith('Debugger attached.') || content.startsWith('Waiting for the debugger to disconnect...'))

front_end/ndb/module.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@
5252
"className": "Ndb.ContextMenuProvider"
5353
}
5454
],
55-
"dependencies": ["common", "sdk", "ndb_sdk", "bindings", "persistence", "components"],
55+
"dependencies": [
56+
"common",
57+
"sdk",
58+
"ndb_sdk",
59+
"bindings",
60+
"persistence",
61+
"components"
62+
],
5663
"scripts": [
5764
"InspectorFrontendHostOverrides.js",
5865
"Connection.js",

services/ndd_service.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function silentRpcErrors(error) {
2323
process.on('uncaughtException', silentRpcErrors);
2424
process.on('unhandledRejection', silentRpcErrors);
2525

26+
const catchedRequests = {};
27+
2628
const DebugState = {
2729
WS_OPEN: 1,
2830
WS_ERROR: 2,
@@ -134,24 +136,41 @@ class NddService {
134136
}
135137

136138
env() {
139+
const pathToHttpPatch = path.resolve(__dirname, '..', './lib/preload/ndb/httpMonkeyPatching.js');
140+
137141
return {
138-
NODE_OPTIONS: `--require ndb/preload.js`,
142+
NODE_OPTIONS: `--require ndb/preload.js --require ${pathToHttpPatch}`,
143+
// NODE_OPTIONS: `--require ndb/preload.js`,
139144
NODE_PATH: `${process.env.NODE_PATH || ''}${path.delimiter}${path.join(__dirname, '..', 'lib', 'preload')}`,
140145
NDD_IPC: this._pipe
141146
};
142147
}
143148

149+
sendMessage(rawMessage) {
150+
const message = JSON.parse(rawMessage);
151+
// send message to frontend directly
152+
// (eg: getResponseBody)
153+
const { base64Encoded, data } = catchedRequests[message.params.requestId];
154+
this._frontend.responseToFrontEnd(message.id, { base64Encoded, body: data });
155+
}
156+
144157
async debug(execPath, args, options) {
145158
const env = this.env();
146159
if (options.data)
147160
env.NDD_DATA = options.data;
161+
148162
const p = spawn(execPath, args, {
149163
cwd: options.cwd,
150164
env: { ...process.env, ...env },
151-
stdio: options.ignoreOutput ? 'ignore' : ['inherit', 'pipe', 'pipe'],
165+
stdio: options.ignoreOutput ? ['ignore', 'ignore', 'ignore', 'ipc'] : ['pipe', 'pipe', 'pipe', 'ipc'],
152166
windowsHide: true
153167
});
154168
if (!options.ignoreOutput) {
169+
p.on('message', ({ type, payload }) => {
170+
if (!(type && payload)) return;
171+
catchedRequests[payload.id] = payload;
172+
this._frontend.sendNetworkData({ type, payload });
173+
});
155174
p.stderr.on('data', data => {
156175
if (process.connected)
157176
this._frontend.terminalData('stderr', data.toString('base64'));

0 commit comments

Comments
 (0)