I am trying to create an extension where: from clicking a button on chrome it will launch a popup window and from that popup window I would like to get information from the initial tab which was focused on the time I've pressed the button.
function onClick(tab) {
var originalTab = tab,
popupTab;
chrome.windows.create(
{
url: chrome.extension.getURL('popup.html'),
type: 'popup'
},
function (w) {
w.getCurrent({populate: true}, function (win) {
var popupTab = win.tabs[0];
popupTab.insertCSS(null, {code: 'body {background:red;}'});
//look now I have access to the original and popup tabs!!!
});
}
);
}
chrome.browserAction.onClicked.addListener(onClick);
By using the following script, nothing really happens.
Where I am creating another window after the button is clicked and when the window is created I am getting the first tab available in it. In this situation I would have access to both originalTab and popupTab instance, but unfortunately this is not what is happening.
Is there particular reason for this script not work as expected?
Thanks in advance