Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google chrome extension get new tab ID

how can i get the new created tab ID after chrome.tabs.create? and what if it was more that one tab create in the same time?

thank you.

like image 782
Ouerghi Yassine Avatar asked Aug 14 '12 01:08

Ouerghi Yassine


People also ask

How can I get current tab ID?

If you send a message from the script, you will have access to a 'sender' object. From there, the tab ID is accessible via 'sender.tab.id'. See http://code.google.com/chrome/extensions/messaging.html for more info. You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.

What is tabId in Chrome?

current tabId is the tab that user can see its content.


2 Answers

The chrome.tabs.create API has the callback function that returns an object containing the new tab details

chrome.tabs.create({"url":url},function(newTab) {
console.log(newTab.id);
});
like image 113
Erisan Olasheni Avatar answered Nov 15 '22 06:11

Erisan Olasheni


ok found the solution

chrome.tabs.onCreated.addListener(function(tab){
    alert("new tab "+tab.id);
});
like image 21
Ouerghi Yassine Avatar answered Nov 15 '22 07:11

Ouerghi Yassine