I have the tabId of a tab. How do I get it's window object?
Bring back a tab or window Windows & Linux: Ctrl + Shift + t. Mac: ⌘ + Shift + t.
The window object as seen inside chrome extensions:
chrome.tabs.get(YOUR_TAB_ID_HERE, function(tab){
chrome.windows.get(tab.windowId, function(win){
console.log(win); // THIS IS THE WINDOW OBJECT
});
});
But if you need the javascript runtime inside a specific tab, you'll need to use Content Scripts which are better explained here:
http://code.google.com/chrome/extensions/content_scripts.html
To get the DOM window object from a tabId, you should insert a content script in that tab:
chrome.tabs.executeScript(tabId, {code:'var w = window; console.log(w);'});
https://developer.chrome.com/extensions/tabs#method-executeScript
Perhaps you'll need to comunicate with your background page:
https://developer.chrome.com/extensions/content_scripts#host-page-communication
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With