How to get the title and URL of the current tab in extension context?

12,575 views
Skip to first unread message

Cristhiam Gabriel Fernández

unread,
Jul 6, 2013, 1:13:35 PM7/6/13
to chromium-...@chromium.org
Hi,
I would like get the title and the URL of the current tab in extension context, i.e. when user do clik on extension icon, it shows the title and the URL in the popup of extension.
I tryed with chrome.tabs.getCurrent but no results, the console shows me undefined.
Anyone can helpme?

PhistucK

unread,
Jul 6, 2013, 1:34:30 PM7/6/13
to Cristhiam Gabriel Fernández, Chromium-extensions
chrome.tabs.getCurrent gets the tab (if any) from which the script is executed (null for browser/page action popup).
Try chrome.tabs.query({active: true, currentWindow: true}, callbackFunction) instead.
Note that the callbackFunction gets an array of Tab objects (may be only one, but within an array), not a single Tab object as a parameter.


PhistucK


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
For more options, visit https://groups.google.com/a/chromium.org/groups/opt_out.
 
 

Minhtrang Vy

unread,
Jul 22, 2014, 2:55:20 PM7/22/14
to chromium-...@chromium.org, cristh...@gmail.com
Hi! I am trying to get the current url or title of the chrome tab that I am on, from my chrome extension. 

In order to do that I am using

            chrome.tabs.query (
                { currentWindow: true, active: true }, 
                function(tabs) {
                    var activeTab = tabs[0];
                    var title = activeTab.title;
                    setMsg(JSON.stringify(activeTab));
             });

setMsg just prints the results out to a div on my chrome extension. The string that it prints out for this page is 
{"active":true,"height":341,"highlighted":true,"id":5726,"incognito":false,"index":14,"openerTabId":5722,"pinned":false,"selected":true,"status":"complete","width":1378,"windowId":1784}
but it does not print out the url or the title attributes of the object. 

I added the "tabs" permissions to my manifest.json. 

   "manifest_version": 2,
   "minimum_chrome_version": "16.0.884",
   "name": "BuilderKit",
   "permissions": [ "tabs", "clipboardWrite", "storage", "\u003Call_urls\u003E" ],
   "short_name": "BuilderKit",
   "version": "1"
}

But when I try to run this in order to check if the permission contains "tabs", it prints out "no go", which  means that the extension does not have the "tabs" permission for some reason... Please refer to the code below:

          chrome.permissions.contains({
            permissions: ['tabs'],
            origins: ['http://www.google.com/']
          }, function(result) {
            if (result) {
              setMsg("got it!");
            } else {
              setMsg("no go");
            }
          });

Why is the "tabs" permissions not recognized? Also, why is it that the url of the page and the title of the page are not available?

PhistucK

unread,
Jul 22, 2014, 5:01:59 PM7/22/14
to Minhtrang Vy, Chromium-extensions, Cristhiam Gabriel Fernández
"\u003Call_urls\u003E" seems weird, replace it with "<all_urls>". Not sure why that does not work, though.

And you better start a new thread instead of reviving an old thread.


PhistucK


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
Reply all
Reply to author
Forward
0 new messages