问题
I am using the chrome extension api chrome.processes and chrome.tabs and have been trying to get the cpu usage of current tab only.
I looked at the chromium example code for reference but the purpose of its code is to display all information of all the processes on chrome but i only need the current tab"s information.
this is my code
var tid;
var cpu;
chrome.tabs.get(tabid, function(tabid) {
tid = tabid.id;
});
chrome.processes.onUpdatedWithMemory.addListener(
function(processes) {
for (pid in processes) {
if (processes[pid].id = tid) {
cpu = processes[pid].id.cpu;
return;
}
}
});
I didn't receive any error message but when I debug it, the value of tid is always undefined and the processes array is looping fine.
来源:https://stackoverflow.com/questions/56844762/how-to-get-cpu-usage-of-current-tab-from-chrome