Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Load the har-export-trigger library (you can include it in your HTML)
- // Example: <script src="https://cdn.jsdelivr.net/npm/har-export-trigger@1.0.0/dist/har-export-trigger.min.js"></script>
- // Function to export HAR data
- function exportHar() {
- // Capture performance entries
- const entries = performance.getEntriesByType('resource');
- // Create a HAR object
- const har = {
- log: {
- version: '1.2',
- creator: {
- name: 'My HAR Exporter',
- version: '1.0',
- },
- entries: entries.map(entry => ({
- startedDateTime: new Date(entry.startTime).toISOString(),
- time: entry.duration,
- request: {
- method: entry.initiatorType,
- url: entry.name,
- },
- response: {
- status: entry.transferSize > 0 ? 200 : 404,
- content: {
- mimeType: entry.initiatorType === 'img' ? 'image/png' : 'text/html',
- },
- },
- })),
- },
- };
- // Convert to JSON
- const harJson = JSON.stringify(har, null, 2);
- // Save as a file (you can modify this part based on your needs)
- const blob = new Blob([harJson], { type: 'application/json' });
- const url = URL.createObjectURL(blob);
- const a = document.createElement('a');
- a.href = url;
- a.download = 'Executor';
- a.click();
- }
- // Call the exportHar function (e.g., via a button click)
- exportHar();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement