Chrome - Detect browser close or tab close
<p>I am using following two listeners on my page when a user closes a tab or window in chrome, but they don't seem to work</p>

<pre><code>chrome.tabs.onRemoved.addListener(function (integer tabId, object removeInfo) {alert("Haooooo")});

chrome.windows.onRemoved.addListener(function (integer windowId) {alert("Haooooo")});
</code></pre>

<p>But, the following function detects the window close or tab close, but gets triggered on refresh too. Has any one have a way to detect the browser/tab close only for Chrome. I am not looking for this to work in any other browser. Looking for a solution only in chrome</p>

<pre><code>window.addEventListener("beforeunload", function (e) {          
          var confirmationMessage = "See you later" ;
          (e || window.event).returnValue = confirmationMessage;
          return confirmationMessage;
}
);
</code></pre>