Bug 1846343 - [remote] Do not emit network events for discarded browsing contexts r=webdriver-reviewers,whimboo

Depends on D187477

Differential Revision: https://phabricator.services.mozilla.com/D187478
This commit is contained in:
Julian Descottes 2023-09-08 13:21:17 +00:00
parent 3f9f4304ec
commit 1cecc01304

View File

@ -447,6 +447,13 @@ class NetworkModule extends Module {
timestamp,
} = data;
const browsingContext = lazy.TabManager.getBrowsingContextById(contextId);
if (!browsingContext) {
// Do not emit events if the context id does not match any existing
// browsing context.
return;
}
const protocolEventName = "network.beforeRequestSent";
const isListening = this.messageHandler.eventsDispatcher.hasListener(
protocolEventName,
@ -476,7 +483,6 @@ class NetworkModule extends Module {
initiator,
});
const browsingContext = lazy.TabManager.getBrowsingContextById(contextId);
this.emitEvent(
protocolEventName,
beforeRequestSentEvent,
@ -511,6 +517,13 @@ class NetworkModule extends Module {
timestamp,
} = data;
const browsingContext = lazy.TabManager.getBrowsingContextById(contextId);
if (!browsingContext) {
// Do not emit events if the context id does not match any existing
// browsing context.
return;
}
const protocolEventName =
name === "response-started"
? "network.responseStarted"
@ -538,7 +551,6 @@ class NetworkModule extends Module {
response: responseData,
});
const browsingContext = lazy.TabManager.getBrowsingContextById(contextId);
this.emitEvent(
protocolEventName,
responseEvent,