views:

91

answers:

3

I am developing an extension for Google Chrome browser. Background script, everytime , authorizes on a server that Though XMPP API, and Subscribed for a PubSub node. I need to unsubscribe on the exit , otherwise the dummy subscriptions are left on the server.

Is There any OnBrowserClose event in Google Chrome API ?

A: 

There is no such event in the Chrome Extension API.

There is however a chrome.windows.onRemoved event that fires each time a window closes. I figured you could check in this event if you closed the last window, but unfortunately due to the asynchronous nature of Chrome this doesn't work.

What I tried was running a simple AJAX request in the onRemoved event handler. The AJAX request never got to the server, as Chrome had already closed before running the event (or just disregarded it).

Making the final answer be: No, currently you can't, as far as I know. You might want to star the following bug report at http://crbug.com/30885 to get noticed on updates.

Manticore
thanks for response, indeed I decided to go in old school way, Just save the previous subscribtion info in the localstorage and unsubscribe it when background script is reloaded =)
simple
A: 

Adding a browser close event is a pretty frequent request. Star http://crbug.com/30885 for updates. And read the bug report for a clever hack to detect when the browser is shut down via a key press.

byoogle
A: 
hondaman