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

Commit f53a5c6

Browse files
committed
polish the code
1 parent 184065c commit f53a5c6

File tree

1 file changed

+34
-38
lines changed

1 file changed

+34
-38
lines changed

front_end/ndb/NetworkInterceptor.js

+34-38
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Ndb.NetworkInterceptor = class extends Ndb.ConnectionInterceptor {
3535

3636
_sendRawMessage(rawMessage) {}
3737

38-
_listen() {
38+
async _listen() {
3939
InspectorFrontendHost.sendMessageToBackend = rawMessage => {
4040
const message = JSON.parse(rawMessage);
4141

@@ -54,7 +54,7 @@ Ndb.NetworkInterceptor = class extends Ndb.ConnectionInterceptor {
5454
id: message.id,
5555
result: {
5656
base64Encoded: true,
57-
body: request.payload.data
57+
body: 'foo'
5858
}
5959
}
6060
);
@@ -63,43 +63,39 @@ Ndb.NetworkInterceptor = class extends Ndb.ConnectionInterceptor {
6363

6464
// we need to setTimeout here because the httpMonkeyPatchingSource is loaded
6565
// after this script
66-
setTimeout(async() => {
67-
while (this._target) {
68-
try {
69-
const raw = await this._target
70-
.runtimeAgent()
71-
.invoke_evaluate({
72-
expression: `process._fetchNetworkMessages()`,
73-
awaitPromise: true,
74-
returnByValue: true
75-
});
76-
77-
const {
78-
result: { value: messages }
79-
} = raw;
80-
81-
if (!messages) return;
82-
83-
// messages is array-like
84-
const messagesArr = Array.from(JSON.parse(messages));
85-
86-
for (const message of messagesArr) {
87-
const { type, payload } = message;
88-
this._cacheRequests.push(message);
89-
90-
// this is on the way back, this way doesn't work
91-
if (type !== 'Network.getResponseBody') {
92-
// but this does
93-
SDK._mainConnection._onMessage(JSON.stringify({
94-
method: type,
95-
params: payload
96-
}));
97-
}
98-
}
99-
} catch (err) {
100-
console.log({ err });
66+
while (this._target) {
67+
const rawResponse = await this._target
68+
.runtimeAgent()
69+
.invoke_evaluate({
70+
expression: `process._fetchNetworkMessages()`,
71+
awaitPromise: true,
72+
returnByValue: true
73+
});
74+
75+
if (!rawResponse || !rawResponse.result) return;
76+
77+
const {
78+
result: { value: messages }
79+
} = rawResponse;
80+
81+
if (!messages) return;
82+
83+
// messages is array-like
84+
const messagesArr = Array.from(JSON.parse(messages));
85+
86+
for (const message of messagesArr) {
87+
const { type, payload } = message;
88+
this._cacheRequests.push(message);
89+
90+
// this is on the way back, this way doesn't work
91+
if (type !== 'Network.getResponseBody') {
92+
// but this does
93+
SDK._mainConnection._onMessage(JSON.stringify({
94+
method: type,
95+
params: payload
96+
}));
10197
}
10298
}
103-
}, 0);
99+
}
104100
}
105101
};

0 commit comments

Comments
 (0)