Skip to content

Commit

Permalink
Bug 1838555 - [devtools] Ignore requests with NS_BINDING_ABORTED, sin…
Browse files Browse the repository at this point in the history
…ce they emmited from the cache r=devtools-reviewers,ochameau

Differential Revision: https://phabricator.services.mozilla.com/D181036
  • Loading branch information
bomsy committed Jul 4, 2023
1 parent 5a74fbc commit b7646d1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
17 changes: 17 additions & 0 deletions devtools/client/netmonitor/test/browser_net_cached-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ add_task(async function () {
},
];

// Cancel the 200 cached request, so that the test can also assert
// that the NS_BINDING_ABORTED status is never displayed for cached requests.
const observer = {
QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
observe(subject, topic, data) {
subject = subject.QueryInterface(Ci.nsIHttpChannel);
if (subject.URI.spec == STATUS_CODES_SJS + "?sts=ok&cached") {
subject.cancel(Cr.NS_BINDING_ABORTED);
Services.obs.removeObserver(
observer,
"http-on-examine-cached-response"
);
}
},
};
Services.obs.addObserver(observer, "http-on-examine-cached-response");

info("Performing requests #1...");
await performRequestsAndWait();

Expand Down
7 changes: 5 additions & 2 deletions devtools/shared/network-observer/NetworkObserver.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export class NetworkObserver {
} else {
// Handles any early blockings e.g by Web Extensions or by CORS
const { blockingExtension, blockedReason } =
lazy.NetworkUtils.getBlockedReason(channel);
lazy.NetworkUtils.getBlockedReason(channel, httpActivity.fromCache);
this.#createNetworkEvent(subject, { blockedReason, blockingExtension });
}
}
Expand Down Expand Up @@ -440,7 +440,10 @@ export class NetworkObserver {
serverTimings
);
} else if (topic === "http-on-failed-opening-request") {
const { blockedReason } = lazy.NetworkUtils.getBlockedReason(channel);
const { blockedReason } = lazy.NetworkUtils.getBlockedReason(
channel,
httpActivity.fromCache
);
this.#createNetworkEvent(channel, { blockedReason });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,10 @@ export class NetworkResponseListener {
// Check any errors or blocking scenarios which happen late in the cycle
// e.g If a host is not found (NS_ERROR_UNKNOWN_HOST) or CORS blocking.
const { blockingExtension, blockedReason } =
lazy.NetworkUtils.getBlockedReason(this.#httpActivity.channel);
lazy.NetworkUtils.getBlockedReason(
this.#httpActivity.channel,
this.#httpActivity.fromCache
);

this.#httpActivity.owner.addResponseContent(response, {
discardResponseBody: this.#httpActivity.discardResponseBody,
Expand Down
10 changes: 8 additions & 2 deletions devtools/shared/network-observer/NetworkUtils.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ function legacyMatchRequest(channel, filters) {
return false;
}

function getBlockedReason(channel) {
function getBlockedReason(channel, fromCache = false) {
let blockingExtension, blockedReason;
const { status } = channel;

Expand All @@ -627,7 +627,7 @@ function getBlockedReason(channel) {
// usually the requests (with these errors) might be displayed with various
// other status codes.
const ignoreList = [
// This is emited when the request is already in the cache.
// These are emited when the request is already in the cache.
"NS_ERROR_PARSED_DATA_CACHED",
// This is emited when there is some issues around images e.g When the img.src
// links to a non existent url. This is typically shown as a 404 request.
Expand All @@ -638,6 +638,12 @@ function getBlockedReason(channel) {
"NS_ERROR_ABORT",
];

// NS_BINDING_ABORTED are emmited when request are abruptly halted, these are valid and should not be ignored.
// They can also be emmited for requests already cache which have the `cached` status, these should be ignored.
if (fromCache) {
ignoreList.push("NS_BINDING_ABORTED");
}

// If the request has not failed or is not blocked by a web extension, check for
// any errors not on the ignore list. e.g When a host is not found (NS_ERROR_UNKNOWN_HOST).
if (
Expand Down

0 comments on commit b7646d1

Please sign in to comment.