I am a newbie for Google Chrome Extensions development ,I wonder how to get a reference to the current tab of current window .
I used chrome.tabs.query({'active': true}
but it doesn't work when multiple windows opened .
Every window that has a tab has one active
tab, so if there are multiple windows open, you need to specify which window you want.
To get the window that the current script is calling from, use:
chrome.tabs.query({ active: true, windowId: chrome.windows.WINDOW_ID_CURRENT }, function (tabs) {
// Do something with tabs
});
If, however, by "current window", you mean the front-most focused window shown to the user, use:
chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
// Do something with tabs
});
For further info, see chrome.tabs.query and Chrome's definition of current window.
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