/* 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/. */
/** * API object for NetMonitor panel (like a facade). This object can be * consumed by other panels, WebExtension API, etc. * * This object doesn't depend on the panel UI and can be created * and used even if the Network panel UI doesn't exist.
*/ function NetMonitorAPI() {
EventEmitter.decorate(this);
// Connector to the backend. this.connector = new Connector();
// List of listeners for `devtools.network.onRequestFinished` WebExt API this._requestFinishedListeners = new Set();
// Register listener for new requests (utilized by WebExtension API). this.on(EVENTS.PAYLOAD_READY, this.onPayloadReady);
// Initialize connection to the backend. Pass `this` as the owner, // so this object can receive all emitted events. const connection = {
toolbox,
owner: this,
};
/** * Clean up (unmount from DOM, remove listeners, disconnect).
*/
destroy() { this.off(EVENTS.PAYLOAD_READY, this.onPayloadReady);
this.connector.disconnect();
if (this.harExportConnector) { this.harExportConnector.disconnect();
}
},
// HAR
/** * Support for `devtools.network.getHAR` (get collected data as HAR)
*/
async getHar() { const {
HarExporter,
} = require("resource://devtools/client/netmonitor/src/har/har-exporter.js"); const state = this.store.getState();
/** * Support for `devtools.network.onRequestFinished`. A hook for * every finished HTTP request used by WebExtensions API.
*/
async onPayloadReady(resource) { if (!this._requestFinishedListeners.size) { return;
}
/** * Support for `Request.getContent` WebExt API (lazy loading response body)
*/
async fetchResponseContent(requestId) { returnthis.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);
},
/** * 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; returnthis.harExportConnector;
}
const connection = {
toolbox: this.toolbox,
};
this.harExportConnector = new Connector(); this.harExportConnectorReady = this.harExportConnector.connect(connection);
/** * 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;
[ zur Elbe Produktseite wechseln0.14Quellennavigators
Analyse erneut starten
]