sitespeedio / chrome-har

Create HAR files from Chrome Debugging Protocol data
MIT License
148 stars 50 forks source link

Problems (i met) in Chrome Extension use #112

Open ieful opened 7 months ago

ieful commented 7 months ago

I'm using chrome-har in my Chrome Extension, all i want is to record a pice of network activity and generate a HAR file.

chrome.debugger.sendCommand({ tabId }, 'Network.enable', {}); chrome.debugger.sendCommand({tabId}, 'Page.enable', {}); As above, i enabled "Network" and "Page" event debugger whitch i investigated they are Required to get HAR data

Then

chrome.debugger.onEvent.addListener(debuggerEventListener);

i add an Listener to Listen the events on the page

and then

const debuggerEventListener = (debuggeeId, method, params) => { if (recording && debuggeeId.tabId === tabId) { if (method !== 'Network.responseReceived') { networkEvents.push({method, params}); } else { const requestId = params.requestId; if (params.response) { chrome.debugger.sendCommand({ tabId: tabId }, "Network.getResponseBody", { requestId: requestId }, function (responseBody) { if (responseBody) { if (responseBody.body) { params.response.body = responseBody.body; networkEvents.push({method, params}); } else { networkEvents.push({method, params}); } } else { console.error('Error fetching response body:', error); networkEvents.push({method, params}); } }); } else { networkEvents.push({method, params}); } } } }

I collect all the event in a Array and i past the Array to harFromMessages Fun

const har = harFromMessages(eventsArrayData, {includeTextFromResponseBody: true, includeResourcesFromDiskCache: true});

The problem is i got pages: [] and entries: [] in the last har result. why???

i printed the eventsArrayData in my console, there is Obviously so many events data collected, but harFromMessages Fun gives me two [] in the result. is seems that harFromMessages dose not push my given event, I'm very confused about this

Looking forward to your answer 🙏

ieful commented 7 months ago

Sorry it seems related with my page Trigger time, now i try 10 times i can get about five or six times works fine, but still not stabilize