jamescridland
jamescridland

Reputation: 745

Getting window ID of just-closed Chrome window using chrome.windows.OnRemoved

I'm writing a simple extension which pops up a window (for a radio player). I want to try and avoid having the extension popping up more than one radio player, so I want to...

  1. set playing=false
  2. If user clicks button, open a window ONLY IF playing=false
  3. When opening window, set "playing=true" and get and store the pop-up window ID
  4. Watch for closed windows, and if it's our pop-up window ID, then set "playing=false".

I'm getting stuck with step 4.

chrome.windows.onRemoved.addListener(function(window) {
    alert (window.id);
});

...this returns "undefined" for the window.id - I'd rather it returned the windowId that has just been closed, so I can do something with it.

What is the obvious thing that I have missed?

ANSWER

chrome.windows.onRemoved.addListener(function(windowId) {
   alert(windowId);
});

...as it happens.

Upvotes: 1

Views: 1439

Answers (1)

serg
serg

Reputation: 111305

chrome.windows.onRemoved returns windowId, not window:

chrome.windows.onRemoved.addListener(function(integer windowId) {...});

Upvotes: 1

Related Questions