Chrome Tab Extensions: getCurrent or getSelected?

I am writing a Chrome extension. As part of the extension, I want to get the URL of the tab from which the extension was called. What is the difference between using:

chrome.tabs.getSelected(null, function(tab) { var myTabUrl = tab.url; });

and

chrome.tabs.getCurrent(function(tab) { var myTabUrl = tab.url; });

?

+5
source share
2 answers

getCurrentshould be what you need getSelected- this is the tab that is currently selected in the browser. When they can be different - perhaps your extension launches some cronjob background in the tabs, so the tab cannot be selected by the user at the moment.

, . getCurrent , (, options.html), . getSelected - , .

- , , . script , , , sender.

+15

chrome.tabs.getSelected . chrome.tabs.query.

chrome.tabs.getSelected. chrome.tabs.query.

+19

All Articles