I'm opening a new window by clicking on the extension button near the search bar. I'd like to open a new window only if it's not already opened; in that case, I'd prefer showing the old one.
Here is my code, but it doesn't work.
var v = null;
var vid = null;
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.windows.getAll({}, function(list) {
// check if already exists
for(window in window_list)
if(window.id == vid) { window.focus(); return; }
chrome.windows.getCurrent(function(w) {
v = chrome.windows.create({'url': 'my_url', 'type': 'panel', 'focused': true});
vid = w.id;
});
});
});
Can someone explain me how to fix it?
Most probably, both v
and vid
values are deleted after closing the app (after it finish to execute the script), but how can I fix it? If possible, without using localStorage or cookies.
I've tried specifying the tabId
properties while creating the window, but it doesn't work.
I've also tried using the chrome.windows.onRemoved.addListener
functionality, but it doesn't work too.