Get the URL of a specific tab?

In Google Chrome, how do I get the URL of the page displayed on a specific tab?

+5
source share
2 answers

It depends on how you define a particular tab. There are many functions for getting a tab, which in turn returns a Tab object . This object has a url attribute.

Take, for example, the currently selected tab. You will get a pen with chrome.tabs.getSelected . Where null is the WindowID and the current window is used by default.

 chrome.tabs.getSelected(null, function(tab) { alert(tab.url); }) 

For more information, I suggest you check out the API documentation .

+6
source

According to the Google Chrome Extensions documentation, you can get the tab url by calling the chrome.tabs.get(integer tabId, function callback) method to get a Tab object containing the following fields:

id (integer) The identifier of the tab. Tab identifiers are unique in a browser session.

index (integer) An index based on the index of the tab in its window.

windowId (integer) The identifier of the window in which the tab is located.

selected (boolean) Regardless of whether the tab is selected.

pinned (boolean) Whether the tab is supported.

url (string) URL displayed by the tab

title (optional string) The title of the tab. This may not be available if the tab is loading.

favIconUrl (optional string) URL of the favicon bookmark. This may not be available if the tab is loading.

status (optional string) Either download or completion.

incognito (boolean) Regardless of whether the tab is in an incognito window.

+2
source

All Articles