Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems (i met) in Chrome Extension use #112

Open
ieful opened this issue Jan 22, 2024 · 1 comment
Open

Problems (i met) in Chrome Extension use #112

ieful opened this issue Jan 22, 2024 · 1 comment

Comments

@ieful
Copy link

ieful commented Jan 22, 2024

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
Copy link
Author

ieful commented Jan 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant