Get Chrome tab pid from Chrome extension -


i'm trying process id associated current tab thru chrome extension.

i did manage thru chrome.processes experimental api.

there way tab pid standard (non-experimental) api ?

if want real process id (i.e. 1 can used other programs identify processes), option chrome.processes, api available on dev channel (so not chrome stable nor beta).

if need identifier uniquely identify processes, can "process id of tab" via chrome.webnavigation api. id meaningful within chrome. before delve details, let's first multiple tabs can share same process id, , 1 tab can contain multiple processes (when site isolation project enabled).

so, "tab pid", assume you're referring process hosts top-level frame. can retrieve list of frames , extract process id tab follows:

background.js

'use strict'; chrome.browseraction.onclicked.addlistener(function(tab) {     chrome.webnavigation.getallframes({         tabid: tab.id,     }, function(details) {         if (chrome.runtime.lasterror) {             alert('error: ' + chrome.runtime.lasterror.message);             return;         }         (var = 0; < details.length; ++i) {             var frame = details[i];             // top-level frame has frame id 0.             if (frame.frameid === 0) {                 alert('tab info:\n' +                       'pid: ' + frame.processid + '\n' +                       'url: ' + frame.url);                 return; // there 1 frame id 0.             }         }         alert('the top-level frame not found!');     }); }); 

manifest.json

{     "name": "show tab pid",     "version": "1",     "manifest_version": 2,     "background": {         "scripts": ["background.js"],         "persistent": false     },     "browser_action": {         "default_title": "show tab pid"     },     "permissions": [         "webnavigation"     ] } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -