st request = getDisplayedRequestById( this.store.getState(), resource.actor ); if (!request) { console.error("HAR: request not found " + resource.actor); return; } const options = { connector, includeResponseBodies: false, items: [request], }; const har = await HarExporter.getHar(options); // There is page so remove the page reference. const harEntry = har.log.entries[0]; delete harEntry.pageref; this._requestFinishedListeners.forEach(listener => listener({ harEntry, requestId: resource.actor, }) ); } /** * Support for `Request.getContent` WebExt API (lazy loading response body) */ async fetchResponseContent(requestId) { return this.connector.requestData(requestId, "responseContent"); } /** * Add listener for `onRequestFinished` events. * * @param {object} listener * The listener to be called it's expected to be * a function that takes ({harEntry, requestId}) * as first argument. */ addRequestFinishedListener(listener) { this._requestFinishedListeners.add(listener); } removeRequestFinishedListener(listener) { this._requestFinishedListeners.delete(listener); } hasRequestFinishedListeners() { return this._requestFinishedListeners.size > 0; } /** * Separate connector for HAR export. */ async getHarExportConnector() { if (this.harExportConnector) { // Wait for the connector to be ready to avoid exceptions if this method is called // twice during its initialization. await this.harExportConnectorReady; return this.harExportConnector; } const connection = { toolbox: this.toolbox, }; this.harExportConnector = new Connector(); this.harExportConnectorReady = this.harExportConnector.connect(connection); await this.harExportConnectorReady; return this.harExportConnector; } /** * Resends a given network request * * @param {string} requestId * Id of the network request */ resendRequest(requestId) { // Flush queued requests. this.store.dispatch(Actions.batchFlush()); // Send custom request with same url, headers and body as the request // with the given requestId. this.store.dispatch(Actions.sendCustomRequest(requestId)); } } exports.NetMonitorAPI = NetMonitorAPI; PK