开发者

google chrome extension onunload event does not work for the last remaining window or tab

I want to fire an event when the last remaining tab or window is closed.

I used window onremoved and tab on removed events in background.html it works but not for the last window.

If i had opened 5 tabs in a window or if i had opened two windows then tab close and window close works only for n-1 tabs and n-1 windows not for the last remaining window or tab.

Why is that? how can we identify that all the windows and tabs got closed to clean up localstorage and some mo开发者_Python百科re stuff?


You can't, with javascript anyway. When the last tab or window is closed your extension is getting closed as well, so your code that tries to catch the event just doesn't exist anymore.

Google created an extension that catches when the last tab is closed, but it does it with NPAPI (dll). If you don't mind C++ you can take a look at its sources.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜