зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset e95324121fde (bug 1625909) for causing multiple devtool failures.
This commit is contained in:
Родитель
a82dc8dfff
Коммит
ce67650fd6
|
@ -742,9 +742,6 @@ Toolbox.prototype = {
|
|||
}
|
||||
},
|
||||
|
||||
_onResourceAvailable() {},
|
||||
_onResourceUpdated() {},
|
||||
|
||||
/**
|
||||
* This method focuses on attaching to one particular target.
|
||||
* It ensure that the target actor is fully initialized and is watching for
|
||||
|
@ -755,6 +752,10 @@ Toolbox.prototype = {
|
|||
async _attachTarget(targetFront) {
|
||||
await targetFront.attach();
|
||||
|
||||
// Start tracking network activity on toolbox open for targets such as tabs.
|
||||
const webConsoleFront = await targetFront.getFront("console");
|
||||
await webConsoleFront.startListeners(["NetworkActivity"]);
|
||||
|
||||
// Do not attach to the thread of additional Frame targets, as they are
|
||||
// already tracked by the content process targets. At least in the context
|
||||
// of the Browser Toolbox.
|
||||
|
@ -842,19 +843,6 @@ Toolbox.prototype = {
|
|||
this._onTargetDestroyed
|
||||
);
|
||||
|
||||
// Start tracking network activity on toolbox open for targets such as tabs.
|
||||
// The listeners attached here do nothing. Doing this just makes sure that
|
||||
// there is always at least one listener existing for network events across
|
||||
// the lifetime of the various panels, so stopping the resource watcher from
|
||||
// clearing out its cache of network event resources.
|
||||
await this.resourceWatcher.watchResources(
|
||||
[this.resourceWatcher.TYPES.NETWORK_EVENT],
|
||||
{
|
||||
onAvailable: this._onResourceAvailable,
|
||||
onUpdated: this._onResourceUpdated,
|
||||
}
|
||||
);
|
||||
|
||||
await domReady;
|
||||
|
||||
this.browserRequire = BrowserLoader({
|
||||
|
@ -3714,14 +3702,6 @@ Toolbox.prototype = {
|
|||
// Reset preferences set by the toolbox
|
||||
outstanding.push(this.resetPreference());
|
||||
|
||||
await this.resourceWatcher.unwatchResources(
|
||||
[this.resourceWatcher.TYPES.NETWORK_EVENT],
|
||||
{
|
||||
onAvailable: this._onResourceAvailable,
|
||||
onUpdated: this._onResourceUpdated,
|
||||
}
|
||||
);
|
||||
|
||||
this.targetList.unwatchTargets(
|
||||
TargetList.ALL_TYPES,
|
||||
this._onTargetAvailable,
|
||||
|
|
|
@ -32,32 +32,145 @@ class WebConsoleFront extends FrontClassWithSpec(webconsoleSpec) {
|
|||
|
||||
// Attribute name from which to retrieve the actorID out of the target actor's form
|
||||
this.formAttributeName = "consoleActor";
|
||||
/**
|
||||
* Holds the network requests currently displayed by the Web Console. Each key
|
||||
* represents the connection ID and the value is network request information.
|
||||
* @private
|
||||
* @type object
|
||||
*/
|
||||
this._networkRequests = new Map();
|
||||
|
||||
this.pendingEvaluationResults = new Map();
|
||||
this.onEvaluationResult = this.onEvaluationResult.bind(this);
|
||||
this._onNetworkEventUpdate = this._onNetworkEventUpdate.bind(this);
|
||||
this.onNetworkEvent = this._onNetworkEvent.bind(this);
|
||||
this.onNetworkEventUpdate = this._onNetworkEventUpdate.bind(this);
|
||||
|
||||
this.on("evaluationResult", this.onEvaluationResult);
|
||||
this.on("serverNetworkEvent", this.onNetworkEvent);
|
||||
this.before("consoleAPICall", this.beforeConsoleAPICall);
|
||||
this.before("pageError", this.beforePageError);
|
||||
|
||||
this._client.on("networkEventUpdate", this._onNetworkEventUpdate);
|
||||
this._client.on("networkEventUpdate", this.onNetworkEventUpdate);
|
||||
}
|
||||
|
||||
getNetworkRequest(actorId) {
|
||||
return this._networkRequests.get(actorId);
|
||||
}
|
||||
|
||||
getNetworkEvents() {
|
||||
return this._networkRequests.values();
|
||||
}
|
||||
|
||||
get actor() {
|
||||
return this.actorID;
|
||||
}
|
||||
|
||||
/**
|
||||
* The "networkEvent" message type handler. We redirect any message to
|
||||
* the UI for displaying.
|
||||
*
|
||||
* @private
|
||||
* @param string type
|
||||
* Message type.
|
||||
* @param object packet
|
||||
* The message received from the server.
|
||||
*/
|
||||
_onNetworkEvent(packet) {
|
||||
const actor = packet.eventActor;
|
||||
const networkInfo = {
|
||||
type: "networkEvent",
|
||||
timeStamp: actor.timeStamp,
|
||||
node: null,
|
||||
actor: actor.actor,
|
||||
discardRequestBody: true,
|
||||
discardResponseBody: true,
|
||||
startedDateTime: actor.startedDateTime,
|
||||
request: {
|
||||
url: actor.url,
|
||||
method: actor.method,
|
||||
},
|
||||
isXHR: actor.isXHR,
|
||||
cause: actor.cause,
|
||||
response: {},
|
||||
timings: {},
|
||||
// track the list of network event updates
|
||||
updates: [],
|
||||
private: actor.private,
|
||||
fromCache: actor.fromCache,
|
||||
fromServiceWorker: actor.fromServiceWorker,
|
||||
isThirdPartyTrackingResource: actor.isThirdPartyTrackingResource,
|
||||
referrerPolicy: actor.referrerPolicy,
|
||||
blockedReason: actor.blockedReason,
|
||||
blockingExtension: actor.blockingExtension,
|
||||
channelId: actor.channelId,
|
||||
};
|
||||
this._networkRequests.set(actor.actor, networkInfo);
|
||||
|
||||
this.emit("networkEvent", networkInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* The "networkEventUpdate" message type handler. We redirect any message to
|
||||
* the UI for displaying.
|
||||
*
|
||||
* @private
|
||||
* @param string type
|
||||
* Message type.
|
||||
* @param object packet
|
||||
* The message received from the server.
|
||||
*/
|
||||
_onNetworkEventUpdate(packet) {
|
||||
this.emit("serverNetworkUpdateEvent", packet);
|
||||
const networkInfo = this.getNetworkRequest(packet.from);
|
||||
if (!networkInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
networkInfo.updates.push(packet.updateType);
|
||||
|
||||
switch (packet.updateType) {
|
||||
case "requestHeaders":
|
||||
networkInfo.request.headersSize = packet.headersSize;
|
||||
break;
|
||||
case "requestPostData":
|
||||
networkInfo.discardRequestBody = packet.discardRequestBody;
|
||||
networkInfo.request.bodySize = packet.dataSize;
|
||||
break;
|
||||
case "responseStart":
|
||||
networkInfo.response.httpVersion = packet.response.httpVersion;
|
||||
networkInfo.response.status = packet.response.status;
|
||||
networkInfo.response.statusText = packet.response.statusText;
|
||||
networkInfo.response.headersSize = packet.response.headersSize;
|
||||
networkInfo.response.remoteAddress = packet.response.remoteAddress;
|
||||
networkInfo.response.remotePort = packet.response.remotePort;
|
||||
networkInfo.discardResponseBody = packet.response.discardResponseBody;
|
||||
networkInfo.response.waitingTime = packet.response.waitingTime;
|
||||
networkInfo.response.content = {
|
||||
mimeType: packet.response.mimeType,
|
||||
};
|
||||
break;
|
||||
case "responseContent":
|
||||
networkInfo.response.content = {
|
||||
mimeType: packet.mimeType,
|
||||
};
|
||||
networkInfo.response.bodySize = packet.contentSize;
|
||||
networkInfo.response.transferredSize = packet.transferredSize;
|
||||
networkInfo.discardResponseBody = packet.discardResponseBody;
|
||||
break;
|
||||
case "eventTimings":
|
||||
networkInfo.totalTime = packet.totalTime;
|
||||
break;
|
||||
case "securityInfo":
|
||||
networkInfo.securityState = packet.state;
|
||||
break;
|
||||
case "responseCache":
|
||||
networkInfo.response.responseCache = packet.responseCache;
|
||||
break;
|
||||
}
|
||||
|
||||
this.emit("networkEventUpdate", {
|
||||
packet: packet,
|
||||
networkInfo,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -474,6 +587,13 @@ class WebConsoleFront extends FrontClassWithSpec(webconsoleSpec) {
|
|||
}
|
||||
}
|
||||
|
||||
clearNetworkRequests() {
|
||||
// Prevent exception if the front has already been destroyed.
|
||||
if (this._networkRequests) {
|
||||
this._networkRequests.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the WebConsoleFront.
|
||||
*
|
||||
|
@ -483,15 +603,18 @@ class WebConsoleFront extends FrontClassWithSpec(webconsoleSpec) {
|
|||
return null;
|
||||
}
|
||||
|
||||
this._client.off("networkEventUpdate", this._onNetworkEventUpdate);
|
||||
this._client.off("networkEventUpdate", this.onNetworkEventUpdate);
|
||||
// This will make future calls to this function harmless because of the early return
|
||||
// at the top of the function.
|
||||
this._client = null;
|
||||
|
||||
this.off("evaluationResult", this.onEvaluationResult);
|
||||
this.off("serverNetworkEvent", this.onNetworkEvent);
|
||||
this._longStrings = null;
|
||||
this.pendingEvaluationResults.clear();
|
||||
this.pendingEvaluationResults = null;
|
||||
this.clearNetworkRequests();
|
||||
this._networkRequests = null;
|
||||
return super.destroy();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// panel.
|
||||
|
||||
const TEST_URI =
|
||||
"data:text/html;charset=UTF-8,<script>console.log(`hello`)</script><p>Switch to inspector on pick</p>";
|
||||
"data:text/html;charset=UTF-8," + "<p>Switch to inspector on pick</p>";
|
||||
const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
|
||||
|
||||
const DATA = [
|
||||
|
@ -20,7 +20,7 @@ const DATA = [
|
|||
start_state: "initial_panel",
|
||||
panel_name: "webconsole",
|
||||
cold: "true",
|
||||
message_count: "1",
|
||||
message_count: "0",
|
||||
width: "1300",
|
||||
},
|
||||
},
|
||||
|
@ -65,7 +65,7 @@ add_task(async function() {
|
|||
|
||||
await startPickerAndAssertSwitchToInspector(toolbox);
|
||||
|
||||
info("Stopping element picker.");
|
||||
info("Stoppping element picker.");
|
||||
await toolbox.nodePicker.stop();
|
||||
|
||||
checkResults();
|
||||
|
|
|
@ -79,6 +79,11 @@ if (window.location.protocol === "chrome:" && url.search.length > 1) {
|
|||
(async function() {
|
||||
try {
|
||||
const target = await targetFromURL(url);
|
||||
|
||||
// Start the network event listening as it is done in the toolbox code
|
||||
const consoleFront = await target.getFront("console");
|
||||
await consoleFront.startListeners(["NetworkActivity"]);
|
||||
|
||||
// Create a fake toolbox object
|
||||
const toolbox = {
|
||||
target,
|
||||
|
|
|
@ -32,6 +32,7 @@ class FirefoxConnector {
|
|||
this.disconnect = this.disconnect.bind(this);
|
||||
this.willNavigate = this.willNavigate.bind(this);
|
||||
this.navigate = this.navigate.bind(this);
|
||||
this.displayCachedEvents = this.displayCachedEvents.bind(this);
|
||||
this.sendHTTPRequest = this.sendHTTPRequest.bind(this);
|
||||
this.setPreferences = this.setPreferences.bind(this);
|
||||
this.triggerActivity = this.triggerActivity.bind(this);
|
||||
|
@ -43,9 +44,9 @@ class FirefoxConnector {
|
|||
|
||||
// Internals
|
||||
this.getLongString = this.getLongString.bind(this);
|
||||
this.getNetworkRequest = this.getNetworkRequest.bind(this);
|
||||
this.onTargetAvailable = this.onTargetAvailable.bind(this);
|
||||
this.onResourceAvailable = this.onResourceAvailable.bind(this);
|
||||
this.onResourceUpdated = this.onResourceUpdated.bind(this);
|
||||
}
|
||||
|
||||
get currentTarget() {
|
||||
|
@ -113,9 +114,7 @@ class FirefoxConnector {
|
|||
}
|
||||
|
||||
async resume() {
|
||||
// On resume, we shoud prevent fetching all cached network events
|
||||
// and only restart recording for the new ones.
|
||||
await this.addListeners(true);
|
||||
await this.addListeners();
|
||||
}
|
||||
|
||||
async onTargetAvailable({ targetFront, isTargetSwitching }) {
|
||||
|
@ -147,35 +146,26 @@ class FirefoxConnector {
|
|||
|
||||
// Initialize Responsive Emulation front for network throttling.
|
||||
this.responsiveFront = await this.currentTarget.getFront("responsive");
|
||||
|
||||
// Displaying cache events is only intended for the UI panel.
|
||||
if (this.actions) {
|
||||
this.displayCachedEvents();
|
||||
}
|
||||
}
|
||||
|
||||
async onResourceAvailable({ resourceType, targetFront, resource }) {
|
||||
const { TYPES } = this.toolbox.resourceWatcher;
|
||||
if (resourceType === TYPES.DOCUMENT_EVENT) {
|
||||
if (resourceType === this.toolbox.resourceWatcher.TYPES.DOCUMENT_EVENT) {
|
||||
this.onDocEvent(resource);
|
||||
return;
|
||||
}
|
||||
|
||||
if (resourceType === TYPES.NETWORK_EVENT) {
|
||||
this.dataProvider.onNetworkResourceAvailable(resource);
|
||||
}
|
||||
}
|
||||
|
||||
async onResourceUpdated({ resourceType, targetFront, resource }) {
|
||||
if (resourceType === this.toolbox.resourceWatcher.TYPES.NETWORK_EVENT) {
|
||||
this.dataProvider.onNetworkResourceUpdated(resource);
|
||||
}
|
||||
}
|
||||
|
||||
async addListeners(ignoreExistingResources = false) {
|
||||
await this.toolbox.resourceWatcher.watchResources(
|
||||
[this.toolbox.resourceWatcher.TYPES.NETWORK_EVENT],
|
||||
{
|
||||
onAvailable: this.onResourceAvailable,
|
||||
onUpdated: this.onResourceUpdated,
|
||||
ignoreExistingResources,
|
||||
}
|
||||
async addListeners() {
|
||||
this.webConsoleFront.on("networkEvent", this.dataProvider.onNetworkEvent);
|
||||
this.webConsoleFront.on(
|
||||
"networkEventUpdate",
|
||||
this.dataProvider.onNetworkEventUpdate
|
||||
);
|
||||
|
||||
// Support for WebSocket monitoring is currently hidden behind this pref.
|
||||
if (Services.prefs.getBoolPref("devtools.netmonitor.features.webSockets")) {
|
||||
try {
|
||||
|
@ -216,13 +206,6 @@ class FirefoxConnector {
|
|||
}
|
||||
|
||||
removeListeners() {
|
||||
this.toolbox.resourceWatcher.unwatchResources(
|
||||
[this.toolbox.resourceWatcher.TYPES.NETWORK_EVENT],
|
||||
{
|
||||
onAvailable: this.onResourceAvailable,
|
||||
onUpdated: this.onResourceUpdated,
|
||||
}
|
||||
);
|
||||
const webSocketFront = this.currentTarget.getCachedFront("webSocket");
|
||||
if (webSocketFront) {
|
||||
webSocketFront.off(
|
||||
|
@ -237,6 +220,17 @@ class FirefoxConnector {
|
|||
webSocketFront.off("frameSent", this.dataProvider.onFrameSent);
|
||||
}
|
||||
|
||||
if (this.webConsoleFront) {
|
||||
this.webConsoleFront.off(
|
||||
"networkEvent",
|
||||
this.dataProvider.onNetworkEvent
|
||||
);
|
||||
this.webConsoleFront.off(
|
||||
"networkEventUpdate",
|
||||
this.dataProvider.onNetworkEventUpdate
|
||||
);
|
||||
}
|
||||
|
||||
const eventSourceFront = this.currentTarget.getCachedFront("eventSource");
|
||||
if (eventSourceFront) {
|
||||
eventSourceFront.off(
|
||||
|
@ -306,6 +300,23 @@ class FirefoxConnector {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display any network events already in the cache.
|
||||
*/
|
||||
displayCachedEvents() {
|
||||
for (const networkInfo of this.webConsoleFront.getNetworkEvents()) {
|
||||
// First add the request to the timeline.
|
||||
this.dataProvider.onNetworkEvent(networkInfo);
|
||||
// Then replay any updates already received.
|
||||
for (const updateType of networkInfo.updates) {
|
||||
this.dataProvider.onNetworkEventUpdate({
|
||||
packet: { updateType },
|
||||
networkInfo,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The "DOMContentLoaded" and "Load" events sent by the console actor.
|
||||
*
|
||||
|
@ -454,6 +465,16 @@ class FirefoxConnector {
|
|||
return Promise.reject(new Error("Invalid activity type"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the network information packet from actor server
|
||||
*
|
||||
* @param {string} id request id
|
||||
* @return {object} networkInfo data packet
|
||||
*/
|
||||
getNetworkRequest(id) {
|
||||
return this.dataProvider.getNetworkRequest(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the full text of a LongString.
|
||||
*
|
||||
|
|
|
@ -48,10 +48,8 @@ class FirefoxDataProvider {
|
|||
this.getLongString = this.getLongString.bind(this);
|
||||
|
||||
// Event handlers
|
||||
this.onNetworkResourceAvailable = this.onNetworkResourceAvailable.bind(
|
||||
this
|
||||
);
|
||||
this.onNetworkResourceUpdated = this.onNetworkResourceUpdated.bind(this);
|
||||
this.onNetworkEvent = this.onNetworkEvent.bind(this);
|
||||
this.onNetworkEventUpdate = this.onNetworkEventUpdate.bind(this);
|
||||
|
||||
this.onWebSocketOpened = this.onWebSocketOpened.bind(this);
|
||||
this.onWebSocketClosed = this.onWebSocketClosed.bind(this);
|
||||
|
@ -81,26 +79,50 @@ class FirefoxDataProvider {
|
|||
* @param {object} data data payload will be added to application state
|
||||
*/
|
||||
async addRequest(id, data) {
|
||||
const { startedDateTime, ...payload } = data;
|
||||
const {
|
||||
method,
|
||||
url,
|
||||
isXHR,
|
||||
cause,
|
||||
startedDateTime,
|
||||
fromCache,
|
||||
fromServiceWorker,
|
||||
isThirdPartyTrackingResource,
|
||||
referrerPolicy,
|
||||
blockedReason,
|
||||
blockingExtension,
|
||||
channelId,
|
||||
} = data;
|
||||
|
||||
// Insert blocked reason in the payload queue as well, as we'll need it later
|
||||
// when deciding if the request is complete.
|
||||
this.pushRequestToQueue(id, {
|
||||
blockedReason: payload.blockedReason,
|
||||
blockedReason,
|
||||
});
|
||||
|
||||
if (this.actionsEnabled && this.actions.addRequest) {
|
||||
await this.actions.addRequest(
|
||||
id,
|
||||
{
|
||||
...payload,
|
||||
// Convert the received date/time string to a unix timestamp.
|
||||
startedMs: Date.parse(startedDateTime),
|
||||
method,
|
||||
url,
|
||||
isXHR,
|
||||
cause,
|
||||
|
||||
// Compatibility code to support Firefox 58 and earlier that always
|
||||
// send stack-trace immediately on networkEvent message.
|
||||
// FF59+ supports fetching the traces lazily via requestData.
|
||||
stacktrace: payload.cause.stacktrace,
|
||||
stacktrace: cause.stacktrace,
|
||||
|
||||
fromCache,
|
||||
fromServiceWorker,
|
||||
isThirdPartyTrackingResource,
|
||||
referrerPolicy,
|
||||
blockedReason,
|
||||
blockingExtension,
|
||||
channelId,
|
||||
},
|
||||
true
|
||||
);
|
||||
|
@ -302,6 +324,16 @@ class FirefoxDataProvider {
|
|||
Object.assign(payloadFromQueue, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the network information packet from actor server
|
||||
*
|
||||
* @param {string} id request id
|
||||
* @return {object} networkInfo data packet
|
||||
*/
|
||||
getNetworkRequest(id) {
|
||||
return this.webConsoleFront.getNetworkRequest(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the full text of a LongString.
|
||||
*
|
||||
|
@ -321,11 +353,11 @@ class FirefoxDataProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* The handler for when the network event resource is available.
|
||||
* The "networkEvent" message type handler.
|
||||
*
|
||||
* @param {object} resource The network event resource
|
||||
* @param {object} networkInfo network request information
|
||||
*/
|
||||
async onNetworkResourceAvailable(resource) {
|
||||
async onNetworkEvent(networkInfo) {
|
||||
const {
|
||||
actor,
|
||||
cause,
|
||||
|
@ -333,34 +365,13 @@ class FirefoxDataProvider {
|
|||
fromServiceWorker,
|
||||
isXHR,
|
||||
request: { method, url },
|
||||
response: { bodySize, ...responseProps },
|
||||
startedDateTime,
|
||||
isThirdPartyTrackingResource,
|
||||
referrerPolicy,
|
||||
blockedReason,
|
||||
blockingExtension,
|
||||
channelId,
|
||||
} = resource;
|
||||
|
||||
// For resources from the resource watcher cache no updates are going to be fired
|
||||
// as the resource already contains all the updated props. These need to be set so
|
||||
// the UI knows the data is available on the backend.
|
||||
const available = {};
|
||||
[
|
||||
"eventTimings",
|
||||
"requestHeaders",
|
||||
"requestPostData",
|
||||
"responseHeaders",
|
||||
"responseStart",
|
||||
"responseContent",
|
||||
"securityInfo",
|
||||
"responseCache",
|
||||
"responseCookies",
|
||||
].forEach(updateType => {
|
||||
if (resource.updates.includes(updateType)) {
|
||||
available[`${updateType}Available`] = true;
|
||||
}
|
||||
});
|
||||
} = networkInfo;
|
||||
|
||||
await this.addRequest(actor, {
|
||||
cause,
|
||||
|
@ -375,55 +386,56 @@ class FirefoxDataProvider {
|
|||
blockedReason,
|
||||
blockingExtension,
|
||||
channelId,
|
||||
mimeType: resource?.content?.mimeType,
|
||||
contentSize: bodySize,
|
||||
...responseProps,
|
||||
...available,
|
||||
});
|
||||
this.emitForTests(TEST_EVENTS.NETWORK_EVENT, resource);
|
||||
|
||||
this.emitForTests(TEST_EVENTS.NETWORK_EVENT, actor);
|
||||
}
|
||||
|
||||
/**
|
||||
* The handler for when the network event resource is updated.
|
||||
* The "networkEventUpdate" message type handler.
|
||||
*
|
||||
* @param {object} resource The updated network event resource.
|
||||
* @param {object} packet the message received from the server.
|
||||
* @param {object} networkInfo the network request information.
|
||||
*/
|
||||
async onNetworkResourceUpdated(resource) {
|
||||
switch (resource.updateType) {
|
||||
async onNetworkEventUpdate(data) {
|
||||
const { packet, networkInfo } = data;
|
||||
const { actor } = networkInfo;
|
||||
const { updateType } = packet;
|
||||
|
||||
switch (updateType) {
|
||||
case "securityInfo":
|
||||
this.pushRequestToQueue(resource.actor, {
|
||||
securityState: resource.securityState,
|
||||
isRacing: resource.isRacing,
|
||||
this.pushRequestToQueue(actor, {
|
||||
securityState: networkInfo.securityState,
|
||||
isRacing: packet.isRacing,
|
||||
});
|
||||
break;
|
||||
case "responseStart":
|
||||
this.pushRequestToQueue(resource.actor, {
|
||||
httpVersion: resource.response.httpVersion,
|
||||
remoteAddress: resource.response.remoteAddress,
|
||||
remotePort: resource.response.remotePort,
|
||||
status: resource.response.status,
|
||||
statusText: resource.response.statusText,
|
||||
headersSize: resource.response.headersSize,
|
||||
waitingTime: resource.response.waitingTime,
|
||||
this.pushRequestToQueue(actor, {
|
||||
httpVersion: networkInfo.response.httpVersion,
|
||||
remoteAddress: networkInfo.response.remoteAddress,
|
||||
remotePort: networkInfo.response.remotePort,
|
||||
status: networkInfo.response.status,
|
||||
statusText: networkInfo.response.statusText,
|
||||
headersSize: networkInfo.response.headersSize,
|
||||
waitingTime: networkInfo.response.waitingTime,
|
||||
});
|
||||
|
||||
// Identify the channel as SSE if mimeType is event-stream.
|
||||
if (resource.response.content.mimeType?.includes("text/event-stream")) {
|
||||
await this.setEventStreamFlag(resource.actor);
|
||||
if (
|
||||
networkInfo.response.content.mimeType?.includes("text/event-stream")
|
||||
) {
|
||||
await this.setEventStreamFlag(actor);
|
||||
}
|
||||
|
||||
this.emitForTests(
|
||||
TEST_EVENTS.STARTED_RECEIVING_RESPONSE,
|
||||
resource.actor
|
||||
);
|
||||
this.emitForTests(TEST_EVENTS.STARTED_RECEIVING_RESPONSE, actor);
|
||||
break;
|
||||
case "responseContent":
|
||||
this.pushRequestToQueue(resource.actor, {
|
||||
contentSize: resource.response.bodySize,
|
||||
transferredSize: resource.response.transferredSize,
|
||||
mimeType: resource.response.content.mimeType,
|
||||
blockingExtension: resource.blockingExtension,
|
||||
blockedReason: resource.blockedReason,
|
||||
this.pushRequestToQueue(actor, {
|
||||
contentSize: networkInfo.response.bodySize,
|
||||
transferredSize: networkInfo.response.transferredSize,
|
||||
mimeType: networkInfo.response.content.mimeType,
|
||||
blockingExtension: packet.blockingExtension,
|
||||
blockedReason: packet.blockedReason,
|
||||
});
|
||||
break;
|
||||
case "eventTimings":
|
||||
|
@ -431,23 +443,19 @@ class FirefoxDataProvider {
|
|||
// in Console panel is using this method to fetch data when network log
|
||||
// is expanded. So, make sure to not push undefined into the payload queue
|
||||
// (it could overwrite an existing value).
|
||||
if (typeof resource.totalTime !== "undefined") {
|
||||
this.pushRequestToQueue(resource.actor, {
|
||||
totalTime: resource.totalTime,
|
||||
});
|
||||
if (typeof networkInfo.totalTime !== "undefined") {
|
||||
this.pushRequestToQueue(actor, { totalTime: networkInfo.totalTime });
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// This available field helps knowing when/if updateType property is arrived
|
||||
// and can be requested via `requestData`
|
||||
this.pushRequestToQueue(resource.actor, {
|
||||
[`${resource.updateType}Available`]: true,
|
||||
});
|
||||
this.pushRequestToQueue(actor, { [`${updateType}Available`]: true });
|
||||
|
||||
await this.onPayloadDataReceived(resource);
|
||||
await this.onPayloadDataReceived(actor);
|
||||
|
||||
this.emitForTests(TEST_EVENTS.NETWORK_EVENT_UPDATED, resource.actor);
|
||||
this.emitForTests(TEST_EVENTS.NETWORK_EVENT_UPDATED, actor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -508,14 +516,14 @@ class FirefoxDataProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* Notify actions when events from onNetworkResourceUpdated are done, updated network event
|
||||
* resources contain initial network info for each updateType and then we can invoke
|
||||
* Notify actions when messages from onNetworkEventUpdate are done, networkEventUpdate
|
||||
* messages contain initial network info for each updateType and then we can invoke
|
||||
* requestData to fetch its corresponded data lazily.
|
||||
* Once all updateTypes of updated network event resource are available, we flush the merged
|
||||
* request payload from pending queue and then update the component.
|
||||
* Once all updateTypes of networkEventUpdate message are arrived, we flush merged
|
||||
* request payload from pending queue and then update component.
|
||||
*/
|
||||
async onPayloadDataReceived(resource) {
|
||||
const payload = this.payloadQueue.get(resource.actor) || {};
|
||||
async onPayloadDataReceived(actor) {
|
||||
const payload = this.payloadQueue.get(actor) || {};
|
||||
|
||||
// For blocked requests, we should only expect the request portions and not
|
||||
// the response portions to be available.
|
||||
|
@ -530,17 +538,17 @@ class FirefoxDataProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
this.payloadQueue.delete(resource.actor);
|
||||
this.payloadQueue.delete(actor);
|
||||
|
||||
if (this.actionsEnabled && this.actions.updateRequest) {
|
||||
await this.actions.updateRequest(resource.actor, payload, true);
|
||||
await this.actions.updateRequest(actor, payload, true);
|
||||
}
|
||||
|
||||
// This event is fired only once per request, once all the properties are fetched
|
||||
// from `onNetworkResourceUpdated`. There should be no more RDP requests after this.
|
||||
// from `onNetworkEventUpdate`. There should be no more RDP requests after this.
|
||||
// Note that this event might be consumed by extension so, emit it in production
|
||||
// release as well.
|
||||
this.emit(EVENTS.PAYLOAD_READY, resource);
|
||||
this.emit(EVENTS.PAYLOAD_READY, actor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -666,7 +674,7 @@ class FirefoxDataProvider {
|
|||
const payload = await this.updateRequest(response.from, {
|
||||
requestHeaders: response,
|
||||
});
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_REQUEST_HEADERS, response);
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_REQUEST_HEADERS, response.from);
|
||||
return payload.requestHeaders;
|
||||
}
|
||||
|
||||
|
@ -679,7 +687,7 @@ class FirefoxDataProvider {
|
|||
const payload = await this.updateRequest(response.from, {
|
||||
responseHeaders: response,
|
||||
});
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_RESPONSE_HEADERS, response);
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_RESPONSE_HEADERS, response.from);
|
||||
return payload.responseHeaders;
|
||||
}
|
||||
|
||||
|
@ -692,7 +700,7 @@ class FirefoxDataProvider {
|
|||
const payload = await this.updateRequest(response.from, {
|
||||
requestCookies: response,
|
||||
});
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_REQUEST_COOKIES, response);
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_REQUEST_COOKIES, response.from);
|
||||
return payload.requestCookies;
|
||||
}
|
||||
|
||||
|
@ -705,7 +713,7 @@ class FirefoxDataProvider {
|
|||
const payload = await this.updateRequest(response.from, {
|
||||
requestPostData: response,
|
||||
});
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_REQUEST_POST_DATA, response);
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_REQUEST_POST_DATA, response.from);
|
||||
return payload.requestPostData;
|
||||
}
|
||||
|
||||
|
@ -718,7 +726,7 @@ class FirefoxDataProvider {
|
|||
const payload = await this.updateRequest(response.from, {
|
||||
securityInfo: response.securityInfo,
|
||||
});
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_SECURITY_INFO, response);
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_SECURITY_INFO, response.from);
|
||||
return payload.securityInfo;
|
||||
}
|
||||
|
||||
|
@ -731,7 +739,7 @@ class FirefoxDataProvider {
|
|||
const payload = await this.updateRequest(response.from, {
|
||||
responseCookies: response,
|
||||
});
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_RESPONSE_COOKIES, response);
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_RESPONSE_COOKIES, response.from);
|
||||
return payload.responseCookies;
|
||||
}
|
||||
|
||||
|
@ -743,7 +751,7 @@ class FirefoxDataProvider {
|
|||
const payload = await this.updateRequest(response.from, {
|
||||
responseCache: response,
|
||||
});
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_RESPONSE_CACHE, response);
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_RESPONSE_CACHE, response.from);
|
||||
return payload.responseCache;
|
||||
}
|
||||
|
||||
|
@ -760,7 +768,7 @@ class FirefoxDataProvider {
|
|||
mimeType: response.content.mimeType,
|
||||
responseContent: response,
|
||||
});
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_RESPONSE_CONTENT, response);
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_RESPONSE_CONTENT, response.from);
|
||||
return payload.responseContent;
|
||||
}
|
||||
|
||||
|
@ -778,7 +786,7 @@ class FirefoxDataProvider {
|
|||
// and running DAMP test doesn't set the `devtools.testing` flag.
|
||||
// So, emit this event even in the production mode.
|
||||
// See also: https://bugzilla.mozilla.org/show_bug.cgi?id=1578215
|
||||
this.emit(EVENTS.RECEIVED_EVENT_TIMINGS, response);
|
||||
this.emit(EVENTS.RECEIVED_EVENT_TIMINGS, response.from);
|
||||
return payload.eventTimings;
|
||||
}
|
||||
|
||||
|
@ -791,7 +799,7 @@ class FirefoxDataProvider {
|
|||
const payload = await this.updateRequest(response.from, {
|
||||
stacktrace: response.stacktrace,
|
||||
});
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_EVENT_STACKTRACE, response);
|
||||
this.emitForTests(TEST_EVENTS.RECEIVED_EVENT_STACKTRACE, response.from);
|
||||
return payload.stacktrace;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ class Connector {
|
|||
this.connectChrome = this.connectChrome.bind(this);
|
||||
this.connectFirefox = this.connectFirefox.bind(this);
|
||||
this.getLongString = this.getLongString.bind(this);
|
||||
this.getNetworkRequest = this.getNetworkRequest.bind(this);
|
||||
this.getTabTarget = this.getTabTarget.bind(this);
|
||||
this.sendHTTPRequest = this.sendHTTPRequest.bind(this);
|
||||
this.setPreferences = this.setPreferences.bind(this);
|
||||
|
@ -83,6 +84,10 @@ class Connector {
|
|||
return this.connector.getLongString(...arguments);
|
||||
}
|
||||
|
||||
getNetworkRequest() {
|
||||
return this.connector.getNetworkRequest(...arguments);
|
||||
}
|
||||
|
||||
getTabTarget() {
|
||||
return this.connector.getTabTarget();
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ HarAutomation.prototype = {
|
|||
// data from events sent from the backend.
|
||||
this.collector = new HarCollector({
|
||||
webConsoleFront: this.webConsoleFront,
|
||||
resourceWatcher: this.toolbox.resourceWatcher,
|
||||
devToolsClient: this.devToolsClient,
|
||||
});
|
||||
|
||||
this.collector.start();
|
||||
|
|
|
@ -17,10 +17,10 @@ const trace = {
|
|||
*/
|
||||
function HarCollector(options) {
|
||||
this.webConsoleFront = options.webConsoleFront;
|
||||
this.resourceWatcher = options.resourceWatcher;
|
||||
this.devToolsClient = options.devToolsClient;
|
||||
|
||||
this.onResourceAvailable = this.onResourceAvailable.bind(this);
|
||||
this.onResourceUpdated = this.onResourceUpdated.bind(this);
|
||||
this.onNetworkEvent = this.onNetworkEvent.bind(this);
|
||||
this.onNetworkEventUpdate = this.onNetworkEventUpdate.bind(this);
|
||||
this.onRequestHeaders = this.onRequestHeaders.bind(this);
|
||||
this.onRequestCookies = this.onRequestCookies.bind(this);
|
||||
this.onRequestPostData = this.onRequestPostData.bind(this);
|
||||
|
@ -35,24 +35,14 @@ function HarCollector(options) {
|
|||
HarCollector.prototype = {
|
||||
// Connection
|
||||
|
||||
start: async function() {
|
||||
await this.resourceWatcher.watchResources(
|
||||
[this.resourceWatcher.TYPES.NETWORK_EVENT],
|
||||
{
|
||||
onAvailable: this.onResourceAvailable,
|
||||
onUpdated: this.onResourceUpdated,
|
||||
}
|
||||
);
|
||||
start: function() {
|
||||
this.webConsoleFront.on("networkEvent", this.onNetworkEvent);
|
||||
this.devToolsClient.on("networkEventUpdate", this.onNetworkEventUpdate);
|
||||
},
|
||||
|
||||
stop: async function() {
|
||||
await this.resourceWatcher.unwatchResources(
|
||||
[this.resourceWatcher.TYPES.NETWORK_EVENT],
|
||||
{
|
||||
onAvailable: this.onResourceAvailable,
|
||||
onUpdated: this.onResourceUpdated,
|
||||
}
|
||||
);
|
||||
stop: function() {
|
||||
this.webConsoleFront.off("networkEvent", this.onNetworkEvent);
|
||||
this.devToolsClient.off("networkEventUpdate", this.onNetworkEventUpdate);
|
||||
},
|
||||
|
||||
clear: function() {
|
||||
|
@ -166,15 +156,15 @@ HarCollector.prototype = {
|
|||
|
||||
// Event Handlers
|
||||
|
||||
onResourceAvailable: function({ resourceType, targetFront, resource }) {
|
||||
trace.log("HarCollector.onNetworkEvent; ", resource);
|
||||
onNetworkEvent: function(packet) {
|
||||
trace.log("HarCollector.onNetworkEvent; ", packet);
|
||||
|
||||
const {
|
||||
actor,
|
||||
startedDateTime,
|
||||
request: { method, url },
|
||||
isXHR,
|
||||
} = resource;
|
||||
} = packet;
|
||||
const startTime = Date.parse(startedDateTime);
|
||||
|
||||
if (this.firstRequestStart == -1) {
|
||||
|
@ -208,19 +198,21 @@ HarCollector.prototype = {
|
|||
this.items.push(file);
|
||||
},
|
||||
|
||||
onResourceUpdated: function({ resourceType, targetFront, resource }) {
|
||||
onNetworkEventUpdate: function(packet) {
|
||||
const actor = packet.from;
|
||||
|
||||
// Skip events from unknown actors (not in the list).
|
||||
// It can happen when there are zombie requests received after
|
||||
// the target is closed or multiple tabs are attached through
|
||||
// one connection (one DevToolsClient object).
|
||||
const file = this.getFile(resource.actor);
|
||||
const file = this.getFile(packet.from);
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
trace.log(
|
||||
"HarCollector.onNetworkEventUpdate; " + resource.updateType,
|
||||
resource
|
||||
"HarCollector.onNetworkEventUpdate; " + packet.updateType,
|
||||
packet
|
||||
);
|
||||
|
||||
const includeResponseBodies = Services.prefs.getBoolPref(
|
||||
|
@ -228,66 +220,62 @@ HarCollector.prototype = {
|
|||
);
|
||||
|
||||
let request;
|
||||
switch (resource.updateType) {
|
||||
switch (packet.updateType) {
|
||||
case "requestHeaders":
|
||||
request = this.getData(
|
||||
resource.actor,
|
||||
actor,
|
||||
"getRequestHeaders",
|
||||
this.onRequestHeaders
|
||||
);
|
||||
break;
|
||||
case "requestCookies":
|
||||
request = this.getData(
|
||||
resource.actor,
|
||||
actor,
|
||||
"getRequestCookies",
|
||||
this.onRequestCookies
|
||||
);
|
||||
break;
|
||||
case "requestPostData":
|
||||
request = this.getData(
|
||||
resource.actor,
|
||||
actor,
|
||||
"getRequestPostData",
|
||||
this.onRequestPostData
|
||||
);
|
||||
break;
|
||||
case "responseHeaders":
|
||||
request = this.getData(
|
||||
resource.actor,
|
||||
actor,
|
||||
"getResponseHeaders",
|
||||
this.onResponseHeaders
|
||||
);
|
||||
break;
|
||||
case "responseCookies":
|
||||
request = this.getData(
|
||||
resource.actor,
|
||||
actor,
|
||||
"getResponseCookies",
|
||||
this.onResponseCookies
|
||||
);
|
||||
break;
|
||||
case "responseStart":
|
||||
file.httpVersion = resource.response.httpVersion;
|
||||
file.status = resource.response.status;
|
||||
file.statusText = resource.response.statusText;
|
||||
file.httpVersion = packet.response.httpVersion;
|
||||
file.status = packet.response.status;
|
||||
file.statusText = packet.response.statusText;
|
||||
break;
|
||||
case "responseContent":
|
||||
file.contentSize = resource.contentSize;
|
||||
file.mimeType = resource.mimeType;
|
||||
file.transferredSize = resource.transferredSize;
|
||||
file.contentSize = packet.contentSize;
|
||||
file.mimeType = packet.mimeType;
|
||||
file.transferredSize = packet.transferredSize;
|
||||
|
||||
if (includeResponseBodies) {
|
||||
request = this.getData(
|
||||
resource.actor,
|
||||
actor,
|
||||
"getResponseContent",
|
||||
this.onResponseContent
|
||||
);
|
||||
}
|
||||
break;
|
||||
case "eventTimings":
|
||||
request = this.getData(
|
||||
resource.actor,
|
||||
"getEventTimings",
|
||||
this.onEventTimings
|
||||
);
|
||||
request = this.getData(actor, "getEventTimings", this.onEventTimings);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ async function performRequestAndWait(tab, monitor) {
|
|||
* Execute simple GET request
|
||||
*/
|
||||
async function performPausedRequest(connector, tab, monitor) {
|
||||
const wait = connector.connector.webConsoleFront.once("serverNetworkEvent");
|
||||
const wait = connector.connector.webConsoleFront.once("networkEvent");
|
||||
await SpecialPowers.spawn(tab.linkedBrowser, [SIMPLE_SJS], async function(
|
||||
url
|
||||
) {
|
||||
|
|
|
@ -265,8 +265,8 @@ function startNetworkEventUpdateObserver(panelWin) {
|
|||
);
|
||||
|
||||
updatedTypes.forEach(type =>
|
||||
panelWin.api.on(type, payload => {
|
||||
const key = payload.from + "-" + type;
|
||||
panelWin.api.on(type, actor => {
|
||||
const key = actor + "-" + type;
|
||||
finishedQueue[key] = finishedQueue[key] ? finishedQueue[key] - 1 : -1;
|
||||
})
|
||||
);
|
||||
|
@ -279,6 +279,7 @@ async function waitForAllNetworkUpdateEvents() {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
info("Wait for completion of all NetworkUpdateEvents packets...");
|
||||
|
@ -330,7 +331,23 @@ function initNetMonitor(url, { requestCount, enableCache = false }) {
|
|||
const markersDone = waitForTimelineMarkers(monitor);
|
||||
await toggleCache(target, true);
|
||||
await Promise.all([requestsDone, markersDone]);
|
||||
info(
|
||||
"Cache disabled when the current and all future toolboxes are open."
|
||||
);
|
||||
|
||||
const consoleFront = await target.getFront("console");
|
||||
|
||||
// Remove any requests generated by the reload while toggling the cache to
|
||||
// avoid interfering with the test.
|
||||
isnot(
|
||||
[...consoleFront.getNetworkEvents()].length,
|
||||
0,
|
||||
"Request to reconfigure the tab was recorded."
|
||||
);
|
||||
info("Clearing requests in the console client.");
|
||||
await consoleFront.clearNetworkRequests();
|
||||
info("Clearing requests in the UI.");
|
||||
|
||||
store.dispatch(Actions.clearRequests());
|
||||
}
|
||||
|
||||
|
@ -380,31 +397,50 @@ function isFiltering(monitor) {
|
|||
function waitForNetworkEvents(monitor, getRequests) {
|
||||
return new Promise(resolve => {
|
||||
const panel = monitor.panelWin;
|
||||
const { getNetworkRequest } = panel.connector;
|
||||
let networkEvent = 0;
|
||||
let nonBlockedNetworkEvent = 0;
|
||||
let payloadReady = 0;
|
||||
let eventTimings = 0;
|
||||
const filtering = isFiltering(monitor);
|
||||
|
||||
function onNetworkEvent(resource) {
|
||||
function onNetworkEvent(actor) {
|
||||
const networkInfo = getNetworkRequest(actor);
|
||||
if (!networkInfo) {
|
||||
// Must have been related to reloading document to disable cache.
|
||||
// Ignore the event.
|
||||
return;
|
||||
}
|
||||
networkEvent++;
|
||||
if (!resource.blockedReason) {
|
||||
if (!networkInfo.blockedReason) {
|
||||
nonBlockedNetworkEvent++;
|
||||
}
|
||||
maybeResolve(TEST_EVENTS.NETWORK_EVENT, resource.actor);
|
||||
maybeResolve(TEST_EVENTS.NETWORK_EVENT, actor, networkInfo);
|
||||
}
|
||||
|
||||
function onPayloadReady(resource) {
|
||||
function onPayloadReady(actor) {
|
||||
const networkInfo = getNetworkRequest(actor);
|
||||
if (!networkInfo) {
|
||||
// Must have been related to reloading document to disable cache.
|
||||
// Ignore the event.
|
||||
return;
|
||||
}
|
||||
payloadReady++;
|
||||
maybeResolve(EVENTS.PAYLOAD_READY, resource.actor);
|
||||
maybeResolve(EVENTS.PAYLOAD_READY, actor, networkInfo);
|
||||
}
|
||||
|
||||
function onEventTimings(response) {
|
||||
function onEventTimings(actor) {
|
||||
const networkInfo = getNetworkRequest(actor);
|
||||
if (!networkInfo) {
|
||||
// Must have been related to reloading document to disable cache.
|
||||
// Ignore the event.
|
||||
return;
|
||||
}
|
||||
eventTimings++;
|
||||
maybeResolve(EVENTS.RECEIVED_EVENT_TIMINGS, response.from);
|
||||
maybeResolve(EVENTS.RECEIVED_EVENT_TIMINGS, actor, networkInfo);
|
||||
}
|
||||
|
||||
function maybeResolve(event, actor) {
|
||||
function maybeResolve(event, actor, networkInfo) {
|
||||
info(
|
||||
"> Network event progress: " +
|
||||
"NetworkEvent: " +
|
||||
|
|
|
@ -146,7 +146,7 @@ function messageRemove(id) {
|
|||
};
|
||||
}
|
||||
|
||||
function networkMessageUpdate(packet, idGenerator = null) {
|
||||
function networkMessageUpdate(packet, idGenerator = null, response) {
|
||||
if (idGenerator == null) {
|
||||
idGenerator = defaultIdGenerator;
|
||||
}
|
||||
|
@ -156,6 +156,7 @@ function networkMessageUpdate(packet, idGenerator = null) {
|
|||
return {
|
||||
type: NETWORK_MESSAGE_UPDATE,
|
||||
message,
|
||||
response,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -175,6 +175,7 @@ function NetworkEventMessage({
|
|||
return serviceContainer.getLongString(grip);
|
||||
},
|
||||
getTabTarget: () => {},
|
||||
getNetworkRequest: () => {},
|
||||
sendHTTPRequest: () => {},
|
||||
setPreferences: () => {},
|
||||
triggerActivity: () => {},
|
||||
|
|
|
@ -17,6 +17,7 @@ function enableMessagesCacheClearing(webConsoleUI) {
|
|||
state = reducer(state, action);
|
||||
|
||||
if (webConsoleUI && action.type === MESSAGES_CLEAR) {
|
||||
webConsoleUI.clearNetworkRequests();
|
||||
webConsoleUI.clearMessagesCache();
|
||||
}
|
||||
return state;
|
||||
|
|
|
@ -50,9 +50,12 @@ function enableNetProvider(webConsoleUI) {
|
|||
const updates = getAllNetworkMessagesUpdateById(newState);
|
||||
const message = updates[action.id];
|
||||
if (message && !message.openedOnce && message.source == "network") {
|
||||
dataProvider.onNetworkResourceAvailable(message);
|
||||
dataProvider.onNetworkEvent(message);
|
||||
message.updates.forEach(updateType => {
|
||||
dataProvider.onNetworkResourceUpdated({ ...message, updateType });
|
||||
dataProvider.onNetworkEventUpdate({
|
||||
packet: { updateType: updateType },
|
||||
networkInfo: message,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -61,15 +64,18 @@ function enableNetProvider(webConsoleUI) {
|
|||
// Network event update packets are sent in batches from:
|
||||
// `WebConsoleOutputWrapper.dispatchMessageUpdate` using
|
||||
// NETWORK_MESSAGE_UPDATE action.
|
||||
// Make sure to call `dataProvider.onNetworkResourceUpdated`
|
||||
// Make sure to call `dataProvider.onNetworkEventUpdate`
|
||||
// to fetch data from the backend.
|
||||
if (type == NETWORK_MESSAGE_UPDATE) {
|
||||
const { actor } = action.message;
|
||||
const { actor } = action.response.networkInfo;
|
||||
const open = getAllMessagesUiById(state).includes(actor);
|
||||
if (open) {
|
||||
const message = getMessage(state, actor);
|
||||
message.updates.forEach(updateType => {
|
||||
dataProvider.onNetworkResourceUpdated({ ...message, updateType });
|
||||
dataProvider.onNetworkEventUpdate({
|
||||
packet: { updateType },
|
||||
networkInfo: message,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,18 +60,15 @@ add_task(async function task() {
|
|||
async function testNetmonitor(toolbox) {
|
||||
const monitor = toolbox.getCurrentPanel();
|
||||
|
||||
const { document, store, windowRequire } = monitor.panelWin;
|
||||
const { store, windowRequire } = monitor.panelWin;
|
||||
const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
|
||||
const { getSortedRequests } = windowRequire(
|
||||
"devtools/client/netmonitor/src/selectors/index"
|
||||
);
|
||||
|
||||
store.dispatch(Actions.batchEnable(false));
|
||||
const requestItem = document.querySelector(".request-list-item");
|
||||
|
||||
await waitUntil(() => store.getState().requests.requests.length > 0);
|
||||
// Lets also wait until all the event timings data requested
|
||||
// has completed and the column is rendered.
|
||||
await waitForDOM(requestItem, ".requests-list-timings-total");
|
||||
|
||||
is(
|
||||
store.getState().requests.requests.length,
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
"use strict";
|
||||
|
||||
const {
|
||||
createResourceWatcherForTab,
|
||||
STUBS_UPDATE_ENV,
|
||||
getStubFile,
|
||||
getCleanedPacket,
|
||||
|
@ -63,52 +62,31 @@ add_task(async function() {
|
|||
});
|
||||
|
||||
async function generateNetworkEventStubs() {
|
||||
const stubs = new Map();
|
||||
const tab = await addTab(TEST_URI);
|
||||
const resourceWatcher = await createResourceWatcherForTab(tab);
|
||||
|
||||
let addNetworkStub = function() {};
|
||||
let addNetworkUpdateStub = function() {};
|
||||
|
||||
const onAvailable = resource => {
|
||||
addNetworkStub(resource);
|
||||
};
|
||||
const onUpdated = resource => {
|
||||
addNetworkUpdateStub(resource);
|
||||
};
|
||||
|
||||
await resourceWatcher.watchResources([resourceWatcher.TYPES.NETWORK_EVENT], {
|
||||
onAvailable,
|
||||
onUpdated,
|
||||
});
|
||||
const packets = new Map();
|
||||
const toolbox = await openNewTabAndToolbox(TEST_URI, "webconsole");
|
||||
const { ui } = toolbox.getCurrentPanel().hud;
|
||||
|
||||
for (const [key, code] of getCommands()) {
|
||||
const noExpectedUpdates = 7;
|
||||
const networkEventDone = new Promise(resolve => {
|
||||
addNetworkStub = ({ resourceType, targetFront, resource }) => {
|
||||
stubs.set(key, getCleanedPacket(key, getOrderedResource(resource)));
|
||||
resolve();
|
||||
};
|
||||
const consoleFront = await toolbox.target.getFront("console");
|
||||
const onNetwork = consoleFront.once("networkEvent", packet => {
|
||||
packets.set(key, getCleanedPacket(key, packet));
|
||||
});
|
||||
const networkEventUpdateDone = new Promise(resolve => {
|
||||
let updateCount = 0;
|
||||
addNetworkUpdateStub = ({ resourceType, targetFront, resource }) => {
|
||||
const updateKey = `${key} update`;
|
||||
// make sure all the updates have been happened
|
||||
if (updateCount >= noExpectedUpdates) {
|
||||
stubs.set(
|
||||
updateKey,
|
||||
// We cannot ensure the form of the resource, some properties
|
||||
// might be in another order than in the original resource.
|
||||
// Hand-picking only what we need should prevent this.
|
||||
getCleanedPacket(updateKey, getOrderedResource(resource))
|
||||
);
|
||||
|
||||
resolve();
|
||||
} else {
|
||||
updateCount++;
|
||||
}
|
||||
const onNetworkUpdate = ui.once("network-message-updated", res => {
|
||||
const updateKey = `${key} update`;
|
||||
// We cannot ensure the form of the network update packet, some properties
|
||||
// might be in another order than in the original packet.
|
||||
// Hand-picking only what we need should prevent this.
|
||||
const packet = {
|
||||
networkInfo: {
|
||||
type: res.networkInfo.type,
|
||||
actor: res.networkInfo.actor,
|
||||
request: res.networkInfo.request,
|
||||
response: res.networkInfo.response,
|
||||
totalTime: res.networkInfo.totalTime,
|
||||
},
|
||||
};
|
||||
packets.set(updateKey, getCleanedPacket(updateKey, packet));
|
||||
});
|
||||
|
||||
await SpecialPowers.spawn(gBrowser.selectedBrowser, [code], function(
|
||||
|
@ -122,42 +100,12 @@ async function generateNetworkEventStubs() {
|
|||
content.wrappedJSObject.triggerPacket();
|
||||
script.remove();
|
||||
});
|
||||
await Promise.all([networkEventDone, networkEventUpdateDone]);
|
||||
|
||||
await Promise.all([onNetwork, onNetworkUpdate]);
|
||||
}
|
||||
resourceWatcher.unwatchResources([resourceWatcher.TYPES.NETWORK_EVENT], {
|
||||
onAvailable,
|
||||
onUpdated,
|
||||
});
|
||||
return stubs;
|
||||
}
|
||||
// Ensures the order of the resource properties
|
||||
function getOrderedResource(resource) {
|
||||
return {
|
||||
resourceType: resource.resourceType,
|
||||
_type: resource._type,
|
||||
timeStamp: resource.timeStamp,
|
||||
node: resource.node,
|
||||
actor: resource.actor,
|
||||
discardRequestBody: resource.discardRequestBody,
|
||||
discardResponseBody: resource.discardResponseBody,
|
||||
startedDateTime: resource.startedDateTime,
|
||||
request: resource.request,
|
||||
isXHR: resource.isXHR,
|
||||
cause: resource.cause,
|
||||
response: resource.response,
|
||||
timings: resource.timings,
|
||||
private: resource.private,
|
||||
fromCache: resource.fromCache,
|
||||
fromServiceWorker: resource.fromServiceWorker,
|
||||
isThirdPartyTrackingResource: resource.isThirdPartyTrackingResource,
|
||||
referrerPolicy: resource.referrerPolicy,
|
||||
blockedReason: resource.blockedReason,
|
||||
channelId: resource.channelId,
|
||||
updates: resource.updates,
|
||||
updateType: resource.updateType,
|
||||
totalTime: resource.totalTime,
|
||||
securityState: resource.securityState,
|
||||
};
|
||||
|
||||
await closeTabAndToolbox();
|
||||
return packets;
|
||||
}
|
||||
|
||||
function getCommands() {
|
||||
|
|
|
@ -209,8 +209,8 @@ function getCleanedPacket(key, packet) {
|
|||
|
||||
if (res.eventActor) {
|
||||
// Clean actor ids and startedDateTime on network messages.
|
||||
res.eventActor.actor = existingPacket.actor;
|
||||
res.eventActor.startedDateTime = existingPacket.startedDateTime;
|
||||
res.eventActor.actor = existingPacket.eventActor.actor;
|
||||
res.eventActor.startedDateTime = existingPacket.eventActor.startedDateTime;
|
||||
}
|
||||
|
||||
if (res.pageError) {
|
||||
|
@ -288,37 +288,54 @@ function getCleanedPacket(key, packet) {
|
|||
res.packet = Object.assign({}, res.packet, override);
|
||||
}
|
||||
|
||||
if (res.startedDateTime) {
|
||||
res.startedDateTime = existingPacket.startedDateTime;
|
||||
if (res.networkInfo) {
|
||||
if (res.networkInfo.startedDateTime) {
|
||||
res.networkInfo.startedDateTime =
|
||||
existingPacket.networkInfo.startedDateTime;
|
||||
}
|
||||
|
||||
if (res.totalTime && existingPacket.totalTime) {
|
||||
res.totalTime = existingPacket.totalTime;
|
||||
if (res.networkInfo.totalTime) {
|
||||
res.networkInfo.totalTime = existingPacket.networkInfo.totalTime;
|
||||
}
|
||||
|
||||
if (res.actor && existingPacket.actor) {
|
||||
res.actor = existingPacket.actor;
|
||||
if (res.networkInfo.actor) {
|
||||
res.networkInfo.actor = existingPacket.networkInfo.actor;
|
||||
}
|
||||
|
||||
if (res?.request?.headersSize && existingPacket?.request?.headersSize) {
|
||||
res.request.headersSize = existingPacket.request.headersSize;
|
||||
if (res.networkInfo.request && res.networkInfo.request.headersSize) {
|
||||
res.networkInfo.request.headersSize =
|
||||
existingPacket.networkInfo.request.headersSize;
|
||||
}
|
||||
|
||||
if (res?.response?.headersSize && existingPacket?.response?.headersSize) {
|
||||
res.response.headersSize = existingPacket.response.headersSize;
|
||||
}
|
||||
if (res?.response?.bodySize && existingPacket?.response?.bodySize) {
|
||||
res.response.bodySize = existingPacket.response.bodySize;
|
||||
if (
|
||||
res.networkInfo.response &&
|
||||
res.networkInfo.response.headersSize !== undefined
|
||||
) {
|
||||
res.networkInfo.response.headersSize =
|
||||
existingPacket.networkInfo.response.headersSize;
|
||||
}
|
||||
if (
|
||||
res?.response?.transferredSize &&
|
||||
existingPacket?.response?.transferredSize
|
||||
res.networkInfo.response &&
|
||||
res.networkInfo.response.bodySize !== undefined
|
||||
) {
|
||||
res.response.transferredSize = existingPacket.response.transferredSize;
|
||||
res.networkInfo.response.bodySize =
|
||||
existingPacket.networkInfo.response.bodySize;
|
||||
}
|
||||
if (
|
||||
res.networkInfo.response &&
|
||||
res.networkInfo.response.transferredSize !== undefined
|
||||
) {
|
||||
res.networkInfo.response.transferredSize =
|
||||
existingPacket.networkInfo.response.transferredSize;
|
||||
}
|
||||
|
||||
if (res?.response?.waitingTime && existingPacket?.response?.waitingTime) {
|
||||
res.response.waitingTime = existingPacket.response.waitingTime;
|
||||
if (
|
||||
res.networkInfo.response &&
|
||||
res.networkInfo.response.waitingTime !== undefined
|
||||
) {
|
||||
res.networkInfo.response.waitingTime =
|
||||
existingPacket.networkInfo.response.waitingTime;
|
||||
}
|
||||
}
|
||||
|
||||
if (res.updates && Array.isArray(res.updates)) {
|
||||
|
@ -331,6 +348,7 @@ function getCleanedPacket(key, packet) {
|
|||
existingPacket.helperResult.object
|
||||
);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -338,12 +356,11 @@ function cleanTimeStamp(packet) {
|
|||
// We want to have the same timestamp for every stub, so they won't be re-sorted when
|
||||
// adding them to the store.
|
||||
const uniqueTimeStamp = 1572867483805;
|
||||
// lowercased timestamp
|
||||
|
||||
if (packet.timestamp) {
|
||||
packet.timestamp = uniqueTimeStamp;
|
||||
}
|
||||
|
||||
// camelcased timestamp
|
||||
if (packet.timeStamp) {
|
||||
packet.timeStamp = uniqueTimeStamp;
|
||||
}
|
||||
|
@ -375,6 +392,10 @@ function cleanTimeStamp(packet) {
|
|||
if (packet?.pageError?.timeStamp) {
|
||||
packet.pageError.timeStamp = uniqueTimeStamp;
|
||||
}
|
||||
|
||||
if (packet?.networkInfo?.timeStamp) {
|
||||
packet.networkInfo.timeStamp = uniqueTimeStamp;
|
||||
}
|
||||
}
|
||||
|
||||
function copyExistingActor(a, b) {
|
||||
|
@ -441,7 +462,9 @@ const stubPackets = parsePacketsWithFronts(rawPackets);
|
|||
|
||||
const stubPreparedMessages = new Map();
|
||||
for (const [key, packet] of Array.from(stubPackets.entries())) {
|
||||
const transformedPacket = prepareMessage(${"packet"}, {
|
||||
const transformedPacket = prepareMessage(${
|
||||
isNetworkMessage ? "packet.networkInfo || packet" : "packet"
|
||||
}, {
|
||||
getNextId: () => "1",
|
||||
});
|
||||
const message = ${
|
||||
|
|
|
@ -68,8 +68,8 @@ describe("WebConsoleWrapper", () => {
|
|||
getPrivatePacket("XHR POST request")
|
||||
);
|
||||
|
||||
const postId = "pid1";
|
||||
const getId = "gid1";
|
||||
const postId = Symbol();
|
||||
const getId = Symbol();
|
||||
|
||||
// Add messages in the store to make sure that update to private requests are
|
||||
// removed from the queue.
|
||||
|
@ -94,11 +94,11 @@ describe("WebConsoleWrapper", () => {
|
|||
publicNetworkUpdate,
|
||||
{
|
||||
...getPrivatePacket("XHR GET request update"),
|
||||
actor: getId,
|
||||
networkInfo: { actor: getId },
|
||||
},
|
||||
{
|
||||
...getPrivatePacket("XHR POST request update"),
|
||||
actor: postId,
|
||||
networkInfo: { actor: postId },
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -19,8 +19,7 @@ const {
|
|||
|
||||
const rawPackets = new Map();
|
||||
rawPackets.set(`GET request`, {
|
||||
"resourceType": "network-event",
|
||||
"_type": "NetworkEvent",
|
||||
"type": "networkEvent",
|
||||
"timeStamp": 1572867483805,
|
||||
"node": null,
|
||||
"actor": "server0.conn0.netEvent4",
|
||||
|
@ -30,119 +29,16 @@ rawPackets.set(`GET request`, {
|
|||
"request": {
|
||||
"url": "http://example.com/inexistent.html",
|
||||
"method": "GET",
|
||||
"headersSize": 385
|
||||
"headersSize": 396
|
||||
},
|
||||
"isXHR": false,
|
||||
"cause": {
|
||||
"type": "img",
|
||||
"loadingDocumentUri": "http://example.com/browser/devtools/client/webconsole/test/browser/stub-generators/test-network-event.html",
|
||||
"stacktraceAvailable": false
|
||||
},
|
||||
"response": {
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"status": "404",
|
||||
"statusText": "Not Found",
|
||||
"headersSize": 160,
|
||||
"remoteAddress": "127.0.0.1",
|
||||
"remotePort": 8888,
|
||||
"content": {
|
||||
"mimeType": "text/html; charset=utf-8"
|
||||
},
|
||||
"bodySize": 418,
|
||||
"transferredSize": 578
|
||||
},
|
||||
"timings": {},
|
||||
"private": false,
|
||||
"isThirdPartyTrackingResource": false,
|
||||
"referrerPolicy": "no-referrer-when-downgrade",
|
||||
"channelId": 265845590720515,
|
||||
"updates": [
|
||||
"eventTimings",
|
||||
"requestCookies",
|
||||
"requestHeaders",
|
||||
"responseContent",
|
||||
"responseCookies",
|
||||
"responseHeaders",
|
||||
"responseStart",
|
||||
"securityInfo"
|
||||
]
|
||||
});
|
||||
|
||||
rawPackets.set(`GET request update`, {
|
||||
"resourceType": "network-event",
|
||||
"_type": "NetworkEvent",
|
||||
"timeStamp": 1572867483805,
|
||||
"node": null,
|
||||
"actor": "server0.conn0.netEvent5",
|
||||
"discardRequestBody": true,
|
||||
"discardResponseBody": false,
|
||||
"startedDateTime": "2020-07-07T14:41:14.572Z",
|
||||
"request": {
|
||||
"url": "http://example.com/inexistent.html",
|
||||
"method": "GET",
|
||||
"headersSize": 385
|
||||
},
|
||||
"isXHR": false,
|
||||
"cause": {
|
||||
"type": "img",
|
||||
"loadingDocumentUri": "http://example.com/browser/devtools/client/webconsole/test/browser/stub-generators/test-network-event.html",
|
||||
"stacktraceAvailable": false
|
||||
},
|
||||
"response": {
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"status": "404",
|
||||
"statusText": "Not Found",
|
||||
"headersSize": 160,
|
||||
"remoteAddress": "127.0.0.1",
|
||||
"remotePort": 8888,
|
||||
"content": {
|
||||
"mimeType": "text/html; charset=utf-8"
|
||||
},
|
||||
"bodySize": 418,
|
||||
"transferredSize": 578
|
||||
},
|
||||
"timings": {},
|
||||
"private": false,
|
||||
"isThirdPartyTrackingResource": false,
|
||||
"referrerPolicy": "no-referrer-when-downgrade",
|
||||
"channelId": 202499118071811,
|
||||
"updates": [
|
||||
"eventTimings",
|
||||
"requestCookies",
|
||||
"requestHeaders",
|
||||
"responseContent",
|
||||
"responseCookies",
|
||||
"responseHeaders",
|
||||
"responseStart",
|
||||
"securityInfo"
|
||||
],
|
||||
"updateType": "responseContent",
|
||||
"totalTime": 3,
|
||||
"securityState": "insecure"
|
||||
});
|
||||
|
||||
rawPackets.set(`XHR GET request`, {
|
||||
"resourceType": "network-event",
|
||||
"_type": "NetworkEvent",
|
||||
"timeStamp": 1572867483805,
|
||||
"node": null,
|
||||
"actor": "server0.conn0.netEvent21",
|
||||
"discardRequestBody": true,
|
||||
"discardResponseBody": true,
|
||||
"startedDateTime": "2020-07-07T14:41:14.612Z",
|
||||
"request": {
|
||||
"url": "http://example.com/inexistent.html",
|
||||
"method": "GET",
|
||||
"headersSize": 385
|
||||
},
|
||||
"isXHR": true,
|
||||
"cause": {
|
||||
"type": "xhr",
|
||||
"loadingDocumentUri": "http://example.com/browser/devtools/client/webconsole/test/browser/stub-generators/test-network-event.html",
|
||||
"lastFrame": {
|
||||
"filename": "http://example.com/browser/devtools/client/webconsole/test/browser/stub-generators/test-network-event.html",
|
||||
"lineNumber": 4,
|
||||
"columnNumber": 5,
|
||||
"lineNumber": 3,
|
||||
"columnNumber": 1,
|
||||
"functionName": "triggerPacket",
|
||||
"asyncCause": null
|
||||
},
|
||||
|
@ -155,6 +51,7 @@ rawPackets.set(`XHR GET request`, {
|
|||
"headersSize": 160,
|
||||
"remoteAddress": "127.0.0.1",
|
||||
"remotePort": 8888,
|
||||
"waitingTime": 2,
|
||||
"content": {
|
||||
"mimeType": "text/html; charset=utf-8"
|
||||
},
|
||||
|
@ -162,30 +59,57 @@ rawPackets.set(`XHR GET request`, {
|
|||
"transferredSize": 578
|
||||
},
|
||||
"timings": {},
|
||||
"updates": [
|
||||
"requestHeaders",
|
||||
"requestCookies",
|
||||
"responseStart",
|
||||
"securityInfo",
|
||||
"responseHeaders",
|
||||
"responseCookies",
|
||||
"eventTimings",
|
||||
"responseContent"
|
||||
],
|
||||
"private": false,
|
||||
"isThirdPartyTrackingResource": false,
|
||||
"referrerPolicy": "no-referrer-when-downgrade",
|
||||
"channelId": 202499118071812,
|
||||
"updates": [
|
||||
"eventTimings",
|
||||
"requestCookies",
|
||||
"requestHeaders",
|
||||
"responseContent",
|
||||
"responseCookies",
|
||||
"responseHeaders",
|
||||
"responseStart",
|
||||
"securityInfo"
|
||||
]
|
||||
"channelId": 265845590720515
|
||||
});
|
||||
|
||||
rawPackets.set(`XHR GET request update`, {
|
||||
"resourceType": "network-event",
|
||||
"_type": "NetworkEvent",
|
||||
rawPackets.set(`GET request update`, {
|
||||
"networkInfo": {
|
||||
"type": "networkEvent",
|
||||
"actor": "server0.conn0.netEvent4",
|
||||
"request": {
|
||||
"url": "http://example.com/inexistent.html",
|
||||
"method": "GET",
|
||||
"headersSize": 396
|
||||
},
|
||||
"response": {
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"status": "404",
|
||||
"statusText": "Not Found",
|
||||
"headersSize": 160,
|
||||
"remoteAddress": "127.0.0.1",
|
||||
"remotePort": 8888,
|
||||
"waitingTime": 2,
|
||||
"content": {
|
||||
"mimeType": "text/html; charset=utf-8"
|
||||
},
|
||||
"bodySize": 418,
|
||||
"transferredSize": 578
|
||||
},
|
||||
"totalTime": 14
|
||||
}
|
||||
});
|
||||
|
||||
rawPackets.set(`XHR GET request`, {
|
||||
"type": "networkEvent",
|
||||
"timeStamp": 1572867483805,
|
||||
"node": null,
|
||||
"actor": "server0.conn0.netEvent20",
|
||||
"discardRequestBody": true,
|
||||
"discardResponseBody": false,
|
||||
"discardResponseBody": true,
|
||||
"startedDateTime": "2019-11-04T11:06:34.909Z",
|
||||
"request": {
|
||||
"url": "http://example.com/inexistent.html",
|
||||
"method": "GET",
|
||||
|
@ -211,6 +135,7 @@ rawPackets.set(`XHR GET request update`, {
|
|||
"headersSize": 160,
|
||||
"remoteAddress": "127.0.0.1",
|
||||
"remotePort": 8888,
|
||||
"waitingTime": 1,
|
||||
"content": {
|
||||
"mimeType": "text/html; charset=utf-8"
|
||||
},
|
||||
|
@ -218,27 +143,51 @@ rawPackets.set(`XHR GET request update`, {
|
|||
"transferredSize": 578
|
||||
},
|
||||
"timings": {},
|
||||
"updates": [
|
||||
"requestHeaders",
|
||||
"requestCookies",
|
||||
"responseStart",
|
||||
"securityInfo",
|
||||
"responseHeaders",
|
||||
"responseCookies",
|
||||
"eventTimings",
|
||||
"responseContent"
|
||||
],
|
||||
"private": false,
|
||||
"isThirdPartyTrackingResource": false,
|
||||
"referrerPolicy": "no-referrer-when-downgrade",
|
||||
"updates": [
|
||||
"eventTimings",
|
||||
"requestCookies",
|
||||
"requestHeaders",
|
||||
"responseContent",
|
||||
"responseCookies",
|
||||
"responseHeaders",
|
||||
"responseStart",
|
||||
"securityInfo"
|
||||
],
|
||||
"updateType": "responseContent",
|
||||
"totalTime": 1,
|
||||
"securityState": "insecure"
|
||||
"channelId": 265845590720516
|
||||
});
|
||||
|
||||
rawPackets.set(`XHR GET request update`, {
|
||||
"networkInfo": {
|
||||
"type": "networkEvent",
|
||||
"actor": "server0.conn0.netEvent20",
|
||||
"request": {
|
||||
"url": "http://example.com/inexistent.html",
|
||||
"method": "GET",
|
||||
"headersSize": 385
|
||||
},
|
||||
"response": {
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"status": "404",
|
||||
"statusText": "Not Found",
|
||||
"headersSize": 160,
|
||||
"remoteAddress": "127.0.0.1",
|
||||
"remotePort": 8888,
|
||||
"waitingTime": 1,
|
||||
"content": {
|
||||
"mimeType": "text/html; charset=utf-8"
|
||||
},
|
||||
"bodySize": 418,
|
||||
"transferredSize": 578
|
||||
},
|
||||
"totalTime": 0
|
||||
}
|
||||
});
|
||||
|
||||
rawPackets.set(`XHR POST request`, {
|
||||
"resourceType": "network-event",
|
||||
"_type": "NetworkEvent",
|
||||
"type": "networkEvent",
|
||||
"timeStamp": 1572867483805,
|
||||
"node": null,
|
||||
"actor": "server0.conn0.netEvent36",
|
||||
|
@ -248,7 +197,7 @@ rawPackets.set(`XHR POST request`, {
|
|||
"request": {
|
||||
"url": "http://example.com/inexistent.html",
|
||||
"method": "POST",
|
||||
"headersSize": 385
|
||||
"headersSize": 433
|
||||
},
|
||||
"isXHR": true,
|
||||
"cause": {
|
||||
|
@ -270,6 +219,7 @@ rawPackets.set(`XHR POST request`, {
|
|||
"headersSize": 160,
|
||||
"remoteAddress": "127.0.0.1",
|
||||
"remotePort": 8888,
|
||||
"waitingTime": 1,
|
||||
"content": {
|
||||
"mimeType": "text/html; charset=utf-8"
|
||||
},
|
||||
|
@ -277,47 +227,30 @@ rawPackets.set(`XHR POST request`, {
|
|||
"transferredSize": 578
|
||||
},
|
||||
"timings": {},
|
||||
"updates": [
|
||||
"requestHeaders",
|
||||
"requestCookies",
|
||||
"responseStart",
|
||||
"securityInfo",
|
||||
"responseHeaders",
|
||||
"responseCookies",
|
||||
"eventTimings",
|
||||
"responseContent"
|
||||
],
|
||||
"private": false,
|
||||
"isThirdPartyTrackingResource": false,
|
||||
"referrerPolicy": "no-referrer-when-downgrade",
|
||||
"channelId": 265845590720517,
|
||||
"updates": [
|
||||
"eventTimings",
|
||||
"requestCookies",
|
||||
"requestHeaders",
|
||||
"responseContent",
|
||||
"responseCookies",
|
||||
"responseHeaders",
|
||||
"responseStart",
|
||||
"securityInfo"
|
||||
]
|
||||
"channelId": 265845590720517
|
||||
});
|
||||
|
||||
rawPackets.set(`XHR POST request update`, {
|
||||
"resourceType": "network-event",
|
||||
"_type": "NetworkEvent",
|
||||
"timeStamp": 1572867483805,
|
||||
"node": null,
|
||||
"networkInfo": {
|
||||
"type": "networkEvent",
|
||||
"actor": "server0.conn0.netEvent36",
|
||||
"discardRequestBody": true,
|
||||
"discardResponseBody": false,
|
||||
"request": {
|
||||
"url": "http://example.com/inexistent.html",
|
||||
"method": "POST",
|
||||
"headersSize": 385
|
||||
},
|
||||
"isXHR": true,
|
||||
"cause": {
|
||||
"type": "xhr",
|
||||
"loadingDocumentUri": "http://example.com/browser/devtools/client/webconsole/test/browser/stub-generators/test-network-event.html",
|
||||
"lastFrame": {
|
||||
"filename": "http://example.com/browser/devtools/client/webconsole/test/browser/stub-generators/test-network-event.html",
|
||||
"lineNumber": 4,
|
||||
"columnNumber": 5,
|
||||
"functionName": "triggerPacket",
|
||||
"asyncCause": null
|
||||
},
|
||||
"stacktraceAvailable": true
|
||||
"headersSize": 433
|
||||
},
|
||||
"response": {
|
||||
"httpVersion": "HTTP/1.1",
|
||||
|
@ -326,29 +259,15 @@ rawPackets.set(`XHR POST request update`, {
|
|||
"headersSize": 160,
|
||||
"remoteAddress": "127.0.0.1",
|
||||
"remotePort": 8888,
|
||||
"waitingTime": 1,
|
||||
"content": {
|
||||
"mimeType": "text/html; charset=utf-8"
|
||||
},
|
||||
"bodySize": 418,
|
||||
"transferredSize": 578
|
||||
},
|
||||
"timings": {},
|
||||
"private": false,
|
||||
"isThirdPartyTrackingResource": false,
|
||||
"referrerPolicy": "no-referrer-when-downgrade",
|
||||
"updates": [
|
||||
"eventTimings",
|
||||
"requestCookies",
|
||||
"requestHeaders",
|
||||
"responseContent",
|
||||
"responseCookies",
|
||||
"responseHeaders",
|
||||
"responseStart",
|
||||
"securityInfo"
|
||||
],
|
||||
"updateType": "responseContent",
|
||||
"totalTime": 2,
|
||||
"securityState": "insecure"
|
||||
"totalTime": 0
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
@ -356,7 +275,7 @@ const stubPackets = parsePacketsWithFronts(rawPackets);
|
|||
|
||||
const stubPreparedMessages = new Map();
|
||||
for (const [key, packet] of Array.from(stubPackets.entries())) {
|
||||
const transformedPacket = prepareMessage(packet, {
|
||||
const transformedPacket = prepareMessage(packet.networkInfo || packet, {
|
||||
getNextId: () => "1",
|
||||
});
|
||||
const message = NetworkEventMessage(transformedPacket);
|
||||
|
|
|
@ -881,9 +881,15 @@ describe("Message reducer:", () => {
|
|||
let updatePacket = clonePacket(stubPackets.get("GET request update"));
|
||||
|
||||
packet.actor = "message1";
|
||||
updatePacket.actor = "message1";
|
||||
updatePacket.networkInfo.actor = "message1";
|
||||
dispatch(actions.messagesAdd([packet]));
|
||||
dispatch(actions.networkMessageUpdate(updatePacket, null));
|
||||
dispatch(
|
||||
actions.networkMessageUpdate(
|
||||
updatePacket.networkInfo,
|
||||
null,
|
||||
updatePacket
|
||||
)
|
||||
);
|
||||
|
||||
let networkUpdates = getAllNetworkMessagesUpdateById(getState());
|
||||
expect(Object.keys(networkUpdates)).toEqual(["message1"]);
|
||||
|
@ -891,9 +897,15 @@ describe("Message reducer:", () => {
|
|||
packet = clonePacket(stubPackets.get("GET request"));
|
||||
updatePacket = stubPackets.get("XHR GET request update");
|
||||
packet.actor = "message2";
|
||||
updatePacket.actor = "message2";
|
||||
updatePacket.networkInfo.actor = "message2";
|
||||
dispatch(actions.messagesAdd([packet]));
|
||||
dispatch(actions.networkMessageUpdate(updatePacket, null));
|
||||
dispatch(
|
||||
actions.networkMessageUpdate(
|
||||
updatePacket.networkInfo,
|
||||
null,
|
||||
updatePacket
|
||||
)
|
||||
);
|
||||
|
||||
networkUpdates = getAllNetworkMessagesUpdateById(getState());
|
||||
expect(Object.keys(networkUpdates)).toEqual(["message1", "message2"]);
|
||||
|
@ -903,7 +915,13 @@ describe("Message reducer:", () => {
|
|||
const { dispatch, getState } = setupStore(["XHR GET request"]);
|
||||
|
||||
const updatePacket = stubPackets.get("XHR GET request update");
|
||||
dispatch(actions.networkMessageUpdate(updatePacket, null));
|
||||
dispatch(
|
||||
actions.networkMessageUpdate(
|
||||
updatePacket.networkInfo,
|
||||
null,
|
||||
updatePacket
|
||||
)
|
||||
);
|
||||
|
||||
let networkUpdates = getAllNetworkMessagesUpdateById(getState());
|
||||
expect(Object.keys(networkUpdates).length > 0).toBe(true);
|
||||
|
@ -927,19 +945,37 @@ describe("Message reducer:", () => {
|
|||
stubPackets.get("XHR GET request update")
|
||||
);
|
||||
packet.actor = "message1";
|
||||
updatePacket.actor = "message1";
|
||||
updatePacket.networkInfo.actor = "message1";
|
||||
dispatch(actions.messagesAdd([packet]));
|
||||
dispatch(actions.networkMessageUpdate(updatePacket, null));
|
||||
dispatch(
|
||||
actions.networkMessageUpdate(
|
||||
updatePacket.networkInfo,
|
||||
null,
|
||||
updatePacket
|
||||
)
|
||||
);
|
||||
|
||||
packet.actor = "message2";
|
||||
updatePacket.actor = "message2";
|
||||
updatePacket.networkInfo.actor = "message2";
|
||||
dispatch(actions.messagesAdd([packet]));
|
||||
dispatch(actions.networkMessageUpdate(updatePacket, null));
|
||||
dispatch(
|
||||
actions.networkMessageUpdate(
|
||||
updatePacket.networkInfo,
|
||||
null,
|
||||
updatePacket
|
||||
)
|
||||
);
|
||||
|
||||
packet.actor = "message3";
|
||||
updatePacket.actor = "message3";
|
||||
updatePacket.networkInfo.actor = "message3";
|
||||
dispatch(actions.messagesAdd([packet]));
|
||||
dispatch(actions.networkMessageUpdate(updatePacket, null));
|
||||
dispatch(
|
||||
actions.networkMessageUpdate(
|
||||
updatePacket.networkInfo,
|
||||
null,
|
||||
updatePacket
|
||||
)
|
||||
);
|
||||
|
||||
// Check that we have the expected data.
|
||||
const messages = getAllMessagesById(getState());
|
||||
|
|
|
@ -35,9 +35,11 @@ describe("Network message reducer:", () => {
|
|||
const updatePacket = clonePacket(stubPackets.get("GET request update"));
|
||||
|
||||
packet.actor = "message1";
|
||||
updatePacket.actor = "message1";
|
||||
updatePacket.networkInfo.actor = "message1";
|
||||
dispatch(actions.messagesAdd([packet]));
|
||||
dispatch(actions.networkMessageUpdate(updatePacket, null));
|
||||
dispatch(
|
||||
actions.networkMessageUpdate(updatePacket.networkInfo, null, updatePacket)
|
||||
);
|
||||
});
|
||||
|
||||
describe("networkMessagesUpdateById", () => {
|
||||
|
|
|
@ -115,7 +115,7 @@ function transformResource(resource) {
|
|||
return transformCSSMessageResource(resource);
|
||||
}
|
||||
|
||||
case ResourceWatcher.TYPES.NETWORK_EVENT: {
|
||||
case "networkEvent": {
|
||||
return transformNetworkEventResource(resource);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,8 +34,11 @@ class WebConsoleConnectionProxy {
|
|||
this.webConsoleUI = webConsoleUI;
|
||||
this.target = target;
|
||||
this.needContentProcessMessagesListener = needContentProcessMessagesListener;
|
||||
|
||||
this._connecter = null;
|
||||
|
||||
this._onNetworkEvent = this._onNetworkEvent.bind(this);
|
||||
this._onNetworkEventUpdate = this._onNetworkEventUpdate.bind(this);
|
||||
this._onTabNavigated = this._onTabNavigated.bind(this);
|
||||
this._onTabWillNavigate = this._onTabWillNavigate.bind(this);
|
||||
this._onLastPrivateContextExited = this._onLastPrivateContextExited.bind(
|
||||
|
@ -78,6 +81,9 @@ class WebConsoleConnectionProxy {
|
|||
);
|
||||
await this.webConsoleUI.setSaveRequestAndResponseBodies(saveBodies);
|
||||
|
||||
const networkMessages = this._getNetworkMessages();
|
||||
this.dispatchMessagesAdd(networkMessages);
|
||||
|
||||
this._addWebConsoleFrontEventListeners();
|
||||
|
||||
if (this.webConsoleFront && !this.webConsoleFront.hasNativeConsoleAPI) {
|
||||
|
@ -116,15 +122,19 @@ class WebConsoleConnectionProxy {
|
|||
* @returns Promise
|
||||
*/
|
||||
_attachConsole() {
|
||||
if (!this.webConsoleFront || !this.needContentProcessMessagesListener) {
|
||||
if (!this.webConsoleFront) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const listeners = ["NetworkActivity"];
|
||||
// Enable the forwarding of console messages to the parent process
|
||||
// when we open the Browser Console or Toolbox without fission support. If Fission
|
||||
// is enabled, we don't use the ContentProcessMessages listener, but attach to the
|
||||
// content processes directly.
|
||||
return this.webConsoleFront.startListeners(["ContentProcessMessages"]);
|
||||
if (this.needContentProcessMessagesListener) {
|
||||
listeners.push("ContentProcessMessages");
|
||||
}
|
||||
return this.webConsoleFront.startListeners(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,6 +147,8 @@ class WebConsoleConnectionProxy {
|
|||
return;
|
||||
}
|
||||
|
||||
this.webConsoleFront.on("networkEvent", this._onNetworkEvent);
|
||||
this.webConsoleFront.on("networkEventUpdate", this._onNetworkEventUpdate);
|
||||
this.webConsoleFront.on(
|
||||
"lastPrivateContextExited",
|
||||
this._onLastPrivateContextExited
|
||||
|
@ -153,6 +165,8 @@ class WebConsoleConnectionProxy {
|
|||
* @private
|
||||
*/
|
||||
_removeWebConsoleFrontEventListeners() {
|
||||
this.webConsoleFront.off("networkEvent", this._onNetworkEvent);
|
||||
this.webConsoleFront.off("networkEventUpdate", this._onNetworkEventUpdate);
|
||||
this.webConsoleFront.off(
|
||||
"lastPrivateContextExited",
|
||||
this._onLastPrivateContextExited
|
||||
|
@ -163,11 +177,51 @@ class WebConsoleConnectionProxy {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get network messages from the server.
|
||||
*
|
||||
* @private
|
||||
* @returns An array of network messages.
|
||||
*/
|
||||
_getNetworkMessages() {
|
||||
if (!this.webConsoleFront) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Array.from(this.webConsoleFront.getNetworkEvents());
|
||||
}
|
||||
|
||||
_clearLogpointMessages(logpointId) {
|
||||
// Some message might try to update while we are closing the toolbox.
|
||||
if (this.webConsoleUI?.wrapper) {
|
||||
if (!this.webConsoleUI?.wrapper) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.webConsoleUI.wrapper.dispatchClearLogpointMessages(logpointId);
|
||||
}
|
||||
|
||||
/**
|
||||
* The "networkEvent" message type handler. We redirect any message to
|
||||
* the UI for displaying.
|
||||
*
|
||||
* @private
|
||||
* @param object networkInfo
|
||||
* The network request information.
|
||||
*/
|
||||
_onNetworkEvent(networkInfo) {
|
||||
this.dispatchMessageAdd(networkInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* The "networkEventUpdate" message type handler. We redirect any message to
|
||||
* the UI for displaying.
|
||||
*
|
||||
* @private
|
||||
* @param object response
|
||||
* The update response received from the server.
|
||||
*/
|
||||
_onNetworkEventUpdate(response) {
|
||||
this.dispatchMessageUpdate(response.networkInfo, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,6 +270,39 @@ class WebConsoleConnectionProxy {
|
|||
this.webConsoleUI.handleTabWillNavigate(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a message add on the new frontend and emit an event for tests.
|
||||
*/
|
||||
dispatchMessageAdd(packet) {
|
||||
// Some message might try to update while we are closing the toolbox.
|
||||
if (!this.webConsoleUI?.wrapper) {
|
||||
return;
|
||||
}
|
||||
this.webConsoleUI.wrapper.dispatchMessageAdd(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Batched dispatch of messages.
|
||||
*/
|
||||
dispatchMessagesAdd(packets) {
|
||||
// Some message might try to update while we are closing the toolbox.
|
||||
if (!this.webConsoleUI?.wrapper) {
|
||||
return;
|
||||
}
|
||||
this.webConsoleUI.wrapper.dispatchMessagesAdd(packets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a message event on the new frontend and emit an event for tests.
|
||||
*/
|
||||
dispatchMessageUpdate(networkInfo, response) {
|
||||
// Some message might try to update while we are closing the toolbox.
|
||||
if (!this.webConsoleUI?.wrapper) {
|
||||
return;
|
||||
}
|
||||
this.webConsoleUI.wrapper.dispatchMessageUpdate(networkInfo, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect the Web Console from the remote server.
|
||||
*
|
||||
|
|
|
@ -79,7 +79,6 @@ class WebConsoleUI {
|
|||
this._onTargetAvailable = this._onTargetAvailable.bind(this);
|
||||
this._onTargetDestroyed = this._onTargetDestroyed.bind(this);
|
||||
this._onResourceAvailable = this._onResourceAvailable.bind(this);
|
||||
this._onResourceUpdated = this._onResourceUpdated.bind(this);
|
||||
|
||||
EventEmitter.decorate(this);
|
||||
}
|
||||
|
@ -236,13 +235,19 @@ class WebConsoleUI {
|
|||
if (this.wrapper) {
|
||||
this.wrapper.dispatchMessagesClear();
|
||||
}
|
||||
|
||||
this.clearNetworkRequests();
|
||||
if (clearStorage) {
|
||||
this.clearMessagesCache();
|
||||
}
|
||||
this.emitForTests("messages-cleared");
|
||||
}
|
||||
|
||||
clearNetworkRequests() {
|
||||
for (const proxy of this.getAllProxies()) {
|
||||
proxy.webConsoleFront.clearNetworkRequests();
|
||||
}
|
||||
}
|
||||
|
||||
clearMessagesCache() {
|
||||
for (const proxy of this.getAllProxies()) {
|
||||
proxy.webConsoleFront.clearMessagesCache();
|
||||
|
@ -337,12 +342,8 @@ class WebConsoleUI {
|
|||
resourceWatcher.TYPES.CONSOLE_MESSAGE,
|
||||
resourceWatcher.TYPES.ERROR_MESSAGE,
|
||||
resourceWatcher.TYPES.PLATFORM_MESSAGE,
|
||||
resourceWatcher.TYPES.NETWORK_EVENT,
|
||||
],
|
||||
{
|
||||
onAvailable: this._onResourceAvailable,
|
||||
onUpdated: this._onResourceUpdated,
|
||||
}
|
||||
{ onAvailable: this._onResourceAvailable }
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -369,12 +370,6 @@ class WebConsoleUI {
|
|||
this.wrapper.dispatchMessageAdd(resource);
|
||||
}
|
||||
|
||||
_onResourceUpdated({ resourceType, targetFront, resource }) {
|
||||
if (resourceType == this.hud.resourceWatcher.TYPES.NETWORK_EVENT) {
|
||||
this.wrapper.dispatchMessageUpdate(resource);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called any time a new target is available.
|
||||
* i.e. it was already existing or has just been created.
|
||||
|
|
|
@ -168,7 +168,9 @@ class WebConsoleWrapper {
|
|||
// since we can receive updates even if the message isn't rendered yet.
|
||||
const messages = [...getAllMessagesById(store.getState()).values()];
|
||||
this.queuedMessageUpdates = this.queuedMessageUpdates.filter(
|
||||
({ actor }) => {
|
||||
({ networkInfo }) => {
|
||||
const { actor } = networkInfo;
|
||||
|
||||
const queuedNetworkMessage = this.queuedMessageAdds.find(
|
||||
p => p.actor === actor
|
||||
);
|
||||
|
@ -208,24 +210,24 @@ class WebConsoleWrapper {
|
|||
store.dispatch(actions.privateMessagesClear());
|
||||
}
|
||||
|
||||
dispatchMessageUpdate(message) {
|
||||
dispatchMessageUpdate(message, res) {
|
||||
// network-message-updated will emit when all the update message arrives.
|
||||
// Since we can't ensure the order of the network update, we check
|
||||
// that message.updates has all we need.
|
||||
// that networkInfo.updates has all we need.
|
||||
// Note that 'requestPostData' is sent only for POST requests, so we need
|
||||
// to count with that.
|
||||
const NUMBER_OF_NETWORK_UPDATE = 8;
|
||||
|
||||
let expectedLength = NUMBER_OF_NETWORK_UPDATE;
|
||||
if (message.updates.includes("responseCache")) {
|
||||
if (res.networkInfo.updates.includes("responseCache")) {
|
||||
expectedLength++;
|
||||
}
|
||||
if (message.updates.includes("requestPostData")) {
|
||||
if (res.networkInfo.updates.includes("requestPostData")) {
|
||||
expectedLength++;
|
||||
}
|
||||
|
||||
if (message.updates.length === expectedLength) {
|
||||
this.batchedMessageUpdates(message);
|
||||
if (res.networkInfo.updates.length === expectedLength) {
|
||||
this.batchedMessageUpdates({ res, message });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,6 +257,7 @@ class WebConsoleWrapper {
|
|||
packet.timeStamp = Date.now();
|
||||
this.dispatchMessageAdd(packet);
|
||||
} else {
|
||||
this.webConsoleUI.clearNetworkRequests();
|
||||
this.dispatchMessagesClear();
|
||||
store.dispatch({
|
||||
type: Constants.WILL_NAVIGATE,
|
||||
|
@ -262,8 +265,8 @@ class WebConsoleWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
batchedMessageUpdates(message) {
|
||||
this.queuedMessageUpdates.push(message);
|
||||
batchedMessageUpdates(info) {
|
||||
this.queuedMessageUpdates.push(info);
|
||||
this.setTimeoutIfNeeded();
|
||||
}
|
||||
|
||||
|
@ -342,9 +345,11 @@ class WebConsoleWrapper {
|
|||
this.queuedMessageAdds = [];
|
||||
|
||||
if (this.queuedMessageUpdates.length > 0) {
|
||||
for (const message of this.queuedMessageUpdates) {
|
||||
await store.dispatch(actions.networkMessageUpdate(message, null));
|
||||
this.webConsoleUI.emitForTests("network-message-updated", message);
|
||||
for (const { message, res } of this.queuedMessageUpdates) {
|
||||
await store.dispatch(
|
||||
actions.networkMessageUpdate(message, null, res)
|
||||
);
|
||||
this.webConsoleUI.emitForTests("network-message-updated", res);
|
||||
}
|
||||
this.queuedMessageUpdates = [];
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ DevToolsModules(
|
|||
'css-changes.js',
|
||||
'css-messages.js',
|
||||
'error-messages.js',
|
||||
'network-events.js',
|
||||
'platform-messages.js',
|
||||
'root-node.js',
|
||||
'stylesheet.js',
|
||||
|
|
|
@ -1,142 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
ResourceWatcher,
|
||||
} = require("devtools/shared/resources/resource-watcher");
|
||||
|
||||
module.exports = async function({
|
||||
targetList,
|
||||
targetFront,
|
||||
isFissionEnabledOnContentToolbox,
|
||||
onAvailable,
|
||||
onUpdated,
|
||||
}) {
|
||||
// Allow the top level target unconditionnally.
|
||||
// Also allow frame, but only in content toolbox, when the fission/content toolbox pref is
|
||||
// set. i.e. still ignore them in the content of the browser toolbox as we inspect
|
||||
// messages via the process targets
|
||||
// Also ignore workers as they are not supported yet. (see bug 1592584)
|
||||
const isContentToolbox = targetList.targetFront.isLocalTab;
|
||||
const listenForFrames = isContentToolbox && isFissionEnabledOnContentToolbox;
|
||||
const isAllowed =
|
||||
targetFront.isTopLevel ||
|
||||
targetFront.targetType === targetList.TYPES.PROCESS ||
|
||||
(targetFront.targetType === targetList.TYPES.FRAME && listenForFrames);
|
||||
|
||||
if (!isAllowed) {
|
||||
return;
|
||||
}
|
||||
|
||||
const webConsoleFront = await targetFront.getFront("console");
|
||||
const _resources = new Map();
|
||||
|
||||
function onNetworkEvent(packet) {
|
||||
const actor = packet.eventActor;
|
||||
const resource = {
|
||||
resourceType: ResourceWatcher.TYPES.NETWORK_EVENT,
|
||||
_type: "NetworkEvent",
|
||||
timeStamp: actor.timeStamp,
|
||||
node: null,
|
||||
actor: actor.actor,
|
||||
discardRequestBody: true,
|
||||
discardResponseBody: true,
|
||||
startedDateTime: actor.startedDateTime,
|
||||
request: {
|
||||
url: actor.url,
|
||||
method: actor.method,
|
||||
},
|
||||
isXHR: actor.isXHR,
|
||||
cause: actor.cause,
|
||||
response: {},
|
||||
timings: {},
|
||||
private: actor.private,
|
||||
fromCache: actor.fromCache,
|
||||
fromServiceWorker: actor.fromServiceWorker,
|
||||
isThirdPartyTrackingResource: actor.isThirdPartyTrackingResource,
|
||||
referrerPolicy: actor.referrerPolicy,
|
||||
blockedReason: actor.blockedReason,
|
||||
channelId: actor.channelId,
|
||||
updates: [],
|
||||
};
|
||||
_resources.set(actor.actor, resource);
|
||||
onAvailable([resource]);
|
||||
}
|
||||
|
||||
function onNetworkEventUpdate(packet) {
|
||||
const resource = _resources.get(packet.from);
|
||||
|
||||
if (!resource) {
|
||||
return;
|
||||
}
|
||||
|
||||
resource.updates.push(packet.updateType);
|
||||
resource.updateType = packet.updateType;
|
||||
|
||||
switch (packet.updateType) {
|
||||
case "requestHeaders":
|
||||
resource.request.headersSize = packet.headersSize;
|
||||
break;
|
||||
case "requestPostData":
|
||||
resource.discardRequestBody = packet.discardRequestBody;
|
||||
resource.request.bodySize = packet.dataSize;
|
||||
break;
|
||||
case "responseStart":
|
||||
resource.response.httpVersion = packet.response.httpVersion;
|
||||
resource.response.status = packet.response.status;
|
||||
resource.response.statusText = packet.response.statusText;
|
||||
resource.response.headersSize = packet.response.headersSize;
|
||||
resource.response.remoteAddress = packet.response.remoteAddress;
|
||||
resource.response.remotePort = packet.response.remotePort;
|
||||
resource.discardResponseBody = packet.response.discardResponseBody;
|
||||
resource.response.content = {
|
||||
mimeType: packet.response.mimeType,
|
||||
};
|
||||
break;
|
||||
case "responseContent":
|
||||
resource.response.content = {
|
||||
mimeType: packet.mimeType,
|
||||
};
|
||||
resource.response.bodySize = packet.contentSize;
|
||||
resource.response.transferredSize = packet.transferredSize;
|
||||
resource.discardResponseBody = packet.discardResponseBody;
|
||||
break;
|
||||
case "eventTimings":
|
||||
resource.totalTime = packet.totalTime;
|
||||
break;
|
||||
case "securityInfo":
|
||||
resource.securityState = packet.state;
|
||||
break;
|
||||
case "responseCache":
|
||||
resource.response.responseCache = packet.responseCache;
|
||||
break;
|
||||
}
|
||||
|
||||
onUpdated(resource);
|
||||
|
||||
if (resource.blockedReason) {
|
||||
// Blocked requests
|
||||
if (
|
||||
resource.updates.includes("requestHeaders") &&
|
||||
resource.updates.includes("requestCookies")
|
||||
) {
|
||||
_resources.delete(resource.actor);
|
||||
}
|
||||
} else if (
|
||||
resource.updates.includes("requestHeaders") &&
|
||||
resource.updates.includes("requestCookies") &&
|
||||
resource.updates.includes("eventTimings") &&
|
||||
resource.updates.includes("responseContent")
|
||||
) {
|
||||
_resources.delete(resource.actor);
|
||||
}
|
||||
}
|
||||
|
||||
webConsoleFront.on("serverNetworkEvent", onNetworkEvent);
|
||||
webConsoleFront.on("serverNetworkUpdateEvent", onNetworkEventUpdate);
|
||||
// Start listening to network events
|
||||
webConsoleFront.startListeners(["NetworkActivity"]);
|
||||
};
|
|
@ -34,7 +34,6 @@ class ResourceWatcher {
|
|||
this._onResourceDestroyed = this._onResourceDestroyed.bind(this);
|
||||
|
||||
this._availableListeners = new EventEmitter();
|
||||
this._updatedListeners = new EventEmitter();
|
||||
this._destroyedListeners = new EventEmitter();
|
||||
|
||||
// Cache for all resources by the order that the resource was taken.
|
||||
|
@ -73,7 +72,6 @@ class ResourceWatcher {
|
|||
async watchResources(resources, options) {
|
||||
const {
|
||||
onAvailable,
|
||||
onUpdated,
|
||||
onDestroyed,
|
||||
ignoreExistingResources = false,
|
||||
} = options;
|
||||
|
@ -107,9 +105,7 @@ class ResourceWatcher {
|
|||
await this._startListening(resource);
|
||||
}
|
||||
this._availableListeners.on(resource, onAvailable);
|
||||
if (onUpdated) {
|
||||
this._updatedListeners.on(resource, onUpdated);
|
||||
}
|
||||
|
||||
if (onDestroyed) {
|
||||
this._destroyedListeners.on(resource, onDestroyed);
|
||||
}
|
||||
|
@ -125,12 +121,9 @@ class ResourceWatcher {
|
|||
* See `watchResources` for the arguments as both methods receive the same.
|
||||
*/
|
||||
unwatchResources(resources, options) {
|
||||
const { onAvailable, onUpdated, onDestroyed } = options;
|
||||
const { onAvailable, onDestroyed } = options;
|
||||
|
||||
for (const resource of resources) {
|
||||
if (onUpdated) {
|
||||
this._updatedListeners.off(resource, onUpdated);
|
||||
}
|
||||
if (onDestroyed) {
|
||||
this._destroyedListeners.off(resource, onDestroyed);
|
||||
}
|
||||
|
@ -302,27 +295,6 @@ class ResourceWatcher {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called either by:
|
||||
* - the backward compatibility code (LegacyListeners)
|
||||
* - target actors RDP events
|
||||
* Called everytime a resource is updated in the remote target.
|
||||
*
|
||||
* @param {Front} targetFront
|
||||
* The Target Front from which this resource comes from.
|
||||
* @param {Array<json/Front>} resources
|
||||
* Depending on the resource Type, it can be an Array composed of either JSON objects or Fronts,
|
||||
* which describes the updated resource.
|
||||
*/
|
||||
_onResourceUpdated(targetFront, resource) {
|
||||
const { resourceType } = resource;
|
||||
this._updatedListeners.emit(resourceType, {
|
||||
resourceType,
|
||||
targetFront,
|
||||
resource,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Called everytime a resource is destroyed in the remote target.
|
||||
* See _onResourceAvailable for the argument description.
|
||||
|
@ -412,13 +384,11 @@ class ResourceWatcher {
|
|||
*/
|
||||
_watchResourcesForTarget(targetFront, resourceType) {
|
||||
const onAvailable = this._onResourceAvailable.bind(this, { targetFront });
|
||||
const onUpdated = this._onResourceUpdated.bind(this, { targetFront });
|
||||
return LegacyListeners[resourceType]({
|
||||
targetList: this.targetList,
|
||||
targetFront,
|
||||
isFissionEnabledOnContentToolbox: gDevTools.isFissionContentToolboxEnabled(),
|
||||
onAvailable,
|
||||
onUpdated,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -486,7 +456,6 @@ ResourceWatcher.TYPES = ResourceWatcher.prototype.TYPES = {
|
|||
DOCUMENT_EVENT: "document-event",
|
||||
ROOT_NODE: "root-node",
|
||||
STYLESHEET: "stylesheet",
|
||||
NETWORK_EVENT: "network-event",
|
||||
};
|
||||
module.exports = { ResourceWatcher };
|
||||
|
||||
|
@ -525,8 +494,6 @@ const LegacyListeners = {
|
|||
.ROOT_NODE]: require("devtools/shared/resources/legacy-listeners/root-node"),
|
||||
[ResourceWatcher.TYPES
|
||||
.STYLESHEET]: require("devtools/shared/resources/legacy-listeners/stylesheet"),
|
||||
[ResourceWatcher.TYPES
|
||||
.NETWORK_EVENT]: require("devtools/shared/resources/legacy-listeners/network-events"),
|
||||
};
|
||||
|
||||
// Optional transformers for each type of resource.
|
||||
|
|
Загрузка…
Ссылка в новой задаче