How to get cpu usage of current tab from chrome

天涯浪子 提交于 2021-01-29 12:57:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!