In a extension I am building, I need to get all the transfer data sizes of all website I am going to visit after clicking on a button. At the end, I will show to total amount of data transferred during one session of test.
Currently in the extension, when I press the button "start", it is going to call some functions from a background.js including adding some listeners. These listeners will be stopped when the user will click on "stop button.
Here is the function called by the listener inside the background file.
function getDataTransferredSize(){
var sum = 0;
if (window.performance === undefined) {
console.log("= Display Size Data: performance NOT supported");
return;
}
var list = window.performance.getEntriesByType("resource");
if (list === undefined) {
console.log("= Display Size Data: performance.getEntriesByType() is NOT supported");
return;
}
console.log("= Display Size Data");
for (var i=0; i < list.length; i++) {
if ("transferSize" in list[i]) {
console.log("... transferSize[" + i + "] = " + list[i].transferSize);
sum = sum + list[i].transferSize;
}
else
console.log("... transferSize[" + i + "] = NOT supported");
}
totalDataTransferredSize += sum;
console.log("Data transf : " + totalDataTransferredSize)
}
the problem is it does not sum up all the sizes of transferred data in each webpage where the extension is opened but it is doing it in the context of the extension. I could not manage to get the sizes outside the extension. Do you have any idea on how to do it ?