{ fromCache: false, fromServiceWorker: false, isCachedResource: false, }); this.#emitWindowGlobalNetworkResource(data.channel, request, response); }; #startListening() { if (this.#subscribedEvents.size == 0) { this.#beforeStopRequestListener.startListening(); this.#cachedResourceListener.startListening(); this.#dataChannelListener.startListening(); } } #stopListening() { if (this.#subscribedEvents.size == 0) { this.#beforeStopRequestListener.stopListening(); this.#cachedResourceListener.stopListening(); this.#dataChannelListener.stopListening(); } } #subscribeEvent(event) { switch (event) { case "network.beforeRequestSent": this.#startListening(); this.#subscribedEvents.add("network.beforeRequestSent"); break; case "network.responseStarted": this.#startListening(); this.#subscribedEvents.add("network.responseStarted"); break; case "network.responseCompleted": this.#startListening(); this.#subscribedEvents.add("network.responseCompleted"); break; } } #unsubscribeEvent(event) { switch (event) { case "network.beforeRequestSent": this.#subscribedEvents.delete("network.beforeRequestSent"); break; case "network.responseStarted": this.#subscribedEvents.delete("network.responseStarted"); break; case "network.responseCompleted": this.#subscribedEvents.delete("network.responseCompleted"); break; } this.#stopListening(); } /** * Internal commands */ _applySessionData(params) { // TODO: Bug 1775231. Move this logic to a shared module or an abstract // class. const { category } = params; if (category === "event") { const filteredSessionData = params.sessionData.filter(item => this.messageHandler.matchesContext(item.contextDescriptor) ); for (const event of this.#subscribedEvents.values()) { const hasSessionItem = filteredSessionData.some( item => item.value === event ); // If there are no session items for this context, we should unsubscribe from the event. if (!hasSessionItem) { this.#unsubscribeEvent(event); } } // Subscribe to all events, which have an item in SessionData. for (const { value } of filteredSessionData) { this.#subscribeEvent(value); } } } } export const network = NetworkModule; PK