How can I get Tabinfo in content script?

7,491 views
Skip to first unread message

Syed Naqvi

unread,
Jul 27, 2010, 6:40:59 PM7/27/10
to Chromium-extensions
Hi,
 
I am trying to get window id and tabid in content script. Any idea how can I get it?
 
Thanks,
-Syed

Brian Kennish

unread,
Jul 28, 2010, 12:11:22 AM7/28/10
to Syed Naqvi, Chromium-extensions
On Tue, Jul 27, 2010 at 3:40 PM, Syed Naqvi <chrom...@gmail.com> wrote:
> I am trying to get window id and tabid in content script. Any idea how can I
> get it?

You'd have to pass the IDs via messages (e.g., from a background page).

But why? You can't call extension methods that take window or tab IDs
(those in the window and tab APIs) from a content script.

Syed Naqvi

unread,
Jul 28, 2010, 3:28:46 PM7/28/10
to Brian Kennish, Chromium-extensions
Hi Brian,
 
Here is my requirement:
 
I have to display an infoBar in OnDOMCompleted() which is in contentScript. To achieve this I send a message to Background page from content script to show the infoBar but it displays the infoBar in the current TAB.
 
 
If I create a new tab while navigation is in progress in previous tab (infoBar suppose to be displayed in this TAB) but infoBar displays in newly created TAB because backgroup page can't differentiate that incoming request is coming from which content script (TAB)?
 
Is there any way to send the tabId and windowId from content script to background page to dispay the infoBar in correct TAB?
 
OR
 
background page may have that info which tab is sending the request?
 
Thanks,
-Syed

Arne Roomann-Kurrik

unread,
Jul 29, 2010, 10:07:17 PM7/29/10
to Syed Naqvi, Brian Kennish, Chromium-extensions
The second argument passed to an onRequest listener is a parameter named "sender" (http://code.google.com/chrome/extensions/extension.html#event-onRequest) - when the message is passed from a content script, this will have a parameter named "tab" indicating which tab the request came from. 

So you can do something like:

chrome.extension.onRequest.addListener(function(request, sender, callback) {
  var tabId = sender.tab.id;
  // ... etc...
};

~Arne 

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.

Reply all
Reply to author
Forward
0 new messages