From 968c7537955ee86e96943d321424b21e8d286448 Mon Sep 17 00:00:00 2001 From: Panos Astithas Date: Mon, 27 Apr 2015 19:59:35 +0300 Subject: [PATCH] Bug 862341 Part 2: Display cached network requests in the web console. r=vporof --- browser/devtools/netmonitor/netmonitor-controller.js | 1 - browser/devtools/webconsole/webconsole.js | 11 +++++++++-- toolkit/devtools/server/actors/webconsole.js | 3 +-- toolkit/devtools/webconsole/client.js | 6 ++++++ toolkit/devtools/webconsole/utils.js | 7 ------- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/browser/devtools/netmonitor/netmonitor-controller.js b/browser/devtools/netmonitor/netmonitor-controller.js index 291361e09a8b..d27c7a99637c 100644 --- a/browser/devtools/netmonitor/netmonitor-controller.js +++ b/browser/devtools/netmonitor/netmonitor-controller.js @@ -440,7 +440,6 @@ function TargetEventsHandler() { TargetEventsHandler.prototype = { get target() NetMonitorController._target, - get webConsoleClient() NetMonitorController.webConsoleClient, /** * Listen for events emitted by the current tab target. diff --git a/browser/devtools/webconsole/webconsole.js b/browser/devtools/webconsole/webconsole.js index 49428606df4d..a7aad564bd56 100644 --- a/browser/devtools/webconsole/webconsole.js +++ b/browser/devtools/webconsole/webconsole.js @@ -1213,6 +1213,9 @@ WebConsoleFrame.prototype = { this.outputMessage(CATEGORY_WEBDEV, this.logConsoleAPIMessage, [aMessage]); break; + case "NetworkEvent": + this.outputMessage(CATEGORY_NETWORK, this.logNetEvent, [aMessage]); + break; } }, this); }, @@ -1546,7 +1549,8 @@ WebConsoleFrame.prototype = { let messageNode = this.createMessageNode(CATEGORY_NETWORK, severity, methodNode, null, null, - clipboardText); + clipboardText, null, + networkInfo.timeStamp); if (networkInfo.private) { messageNode.setAttribute("private", true); } @@ -5140,7 +5144,10 @@ WebConsoleConnectionProxy.prototype = { Cu.reportError("Web Console getCachedMessages error: invalid state."); } - this.owner.displayCachedMessages(aResponse.messages); + let messages = aResponse.messages.concat(...this.webConsoleClient.getNetworkEvents()); + messages.sort((a, b) => a.timeStamp - b.timeStamp); + + this.owner.displayCachedMessages(messages); if (!this._hasNativeConsoleAPI) { this.owner.logWarningAboutReplacedAPI(); diff --git a/toolkit/devtools/server/actors/webconsole.js b/toolkit/devtools/server/actors/webconsole.js index e6a91bed707c..3356cb8bc899 100644 --- a/toolkit/devtools/server/actors/webconsole.js +++ b/toolkit/devtools/server/actors/webconsole.js @@ -734,8 +734,6 @@ WebConsoleActor.prototype = } } - messages.sort(function(a, b) { return a.timeStamp - b.timeStamp; }); - return { from: this.actorID, messages: messages, @@ -1606,6 +1604,7 @@ NetworkEventActor.prototype = return { actor: this.actorID, startedDateTime: this._startedDateTime, + timeStamp: Date.parse(this._startedDateTime), url: this._request.url, method: this._request.method, isXHR: this._isXHR, diff --git a/toolkit/devtools/webconsole/client.js b/toolkit/devtools/webconsole/client.js index f6221cd7747f..8f868655077e 100644 --- a/toolkit/devtools/webconsole/client.js +++ b/toolkit/devtools/webconsole/client.js @@ -68,6 +68,10 @@ WebConsoleClient.prototype = { this._networkRequests.delete(actorId); }, + getNetworkEvents() { + return this._networkRequests.values(); + }, + get actor() { return this._actor; }, /** @@ -85,6 +89,8 @@ WebConsoleClient.prototype = { if (packet.from == this._actor) { let actor = packet.eventActor; let networkInfo = { + _type: "NetworkEvent", + timeStamp: actor.timeStamp, node: null, actor: actor.actor, discardRequestBody: true, diff --git a/toolkit/devtools/webconsole/utils.js b/toolkit/devtools/webconsole/utils.js index 3dbd397a39e5..cfec471f00c8 100644 --- a/toolkit/devtools/webconsole/utils.js +++ b/toolkit/devtools/webconsole/utils.js @@ -1496,13 +1496,6 @@ ConsoleAPIListener.prototype = messages = messages.filter((m) => m.consoleID == this.consoleID); } - // ConsoleAPIStorage gives up messages sorted, but we ask for different - // blocks of events and we must sort them again in order to show them in the - // proper order. - messages = messages.sort(function(a, b) { - return a.timeStamp - b.timeStamp; - }); - if (aIncludePrivate) { return messages; }