class NetworkInspector {
constructor() {
this.requests = new Map();
}
startMonitoring() {
const originalFetch = window.fetch;
window.fetch = async (...args) => {
const requestId = Math.random().toString(36).slice(2);
const startTime = Date.now();
this.requests.set(requestId, {
url: args[0],
startTime,
status: 'pending'
});
try {
const response = await originalFetch(...args);
this.requests.set(requestId, {
...this.requests.get(requestId),
status: 'complete',
duration: Date.now() - startTime,
responseStatus: response.status
});
return response;
} catch (error) {
this.requests.set(requestId, {
...this.requests.get(requestId),
status: 'error',
duration: Date.now() - startTime,
error: error.message
});
throw error;
}
};
}
getRequestLog() {
return Array.from(this.requests.values());
}
}