diff --git a/front_end/ndb/InspectorFrontendHostOverrides.js b/front_end/ndb/InspectorFrontendHostOverrides.js index 6bae7c60..58179133 100644 --- a/front_end/ndb/InspectorFrontendHostOverrides.js +++ b/front_end/ndb/InspectorFrontendHostOverrides.js @@ -58,5 +58,25 @@ } }; + while (true) { + const message = await target.runtimeAgent().invoke_evaluate({ + expression: 'process._getNetworkMessages()', + awaitPromise: true + }); + + if (!message.result) return; + const arrMessages = JSON.parse(message.result.value); + + for (const mes of arrMessages) { + const { type, payload } = mes; + + if (type) { + SDK._mainConnection._onMessage(JSON.stringify({ + method: type, + params: payload + })); + } + } + } })(); diff --git a/lib/preload/ndb/httpMonkeyPatching.js b/lib/preload/ndb/httpMonkeyPatching.js index e0a31dd0..a494e6af 100644 --- a/lib/preload/ndb/httpMonkeyPatching.js +++ b/lib/preload/ndb/httpMonkeyPatching.js @@ -43,7 +43,6 @@ const getId = () => id++; let messages = []; let messageAdded = null; -// this function is our instrumentation, to report anything to frontend - call it instead of process.send function reportMessage(message) { messages.push(message); if (messageAdded) { @@ -52,7 +51,6 @@ function reportMessage(message) { } } -// this function should be called from frontend in the loop using `target.runtimeAgent().invoke_evaluate` process._getNetworkMessages = async function() { if (!messages.length) await new Promise(resolve => messageAdded = resolve); @@ -61,20 +59,10 @@ process._getNetworkMessages = async function() { process._sendMessage = async function(rawMessage) { return new Promise(resolve => { - setTimeout(() => { - console.log({ rawMessage }); - const message = rawMessage; - console.log({ message }); - // send message to frontend directly - // (eg: getResponseBody) - console.log({ cacheRequests }); - console.log({ foo: cacheRequests[message.params.requestId] }); - - if (!cacheRequests[message.params.requestId]) { - resolve(JSON.stringify({})); - return; - } - + const message = rawMessage; + if (!cacheRequests[message.params.requestId]) { + resolve(JSON.stringify({})); + } else { if (message.method === 'Network.getResponseBody') { const { base64Encoded, data } = cacheRequests[message.params.requestId]; @@ -82,7 +70,7 @@ process._sendMessage = async function(rawMessage) { console.log({ data }); resolve(JSON.stringify([message.id, { base64Encoded, body: data }])); } - }, 0); + } }); }; @@ -127,8 +115,6 @@ const callbackWrapper = (callback, req) => res => { base64Encoded: true }; - console.log({ bar: cacheRequests[res.req.__requestId] }); - const payload = { id: res.req.__requestId, requestId: res.req.__requestId,