针对Google Chrome扩展程序的事件onBrowser关闭? [英] Event onBrowserClose for Google Chrome Extension?

查看:122
本文介绍了针对Google Chrome扩展程序的事件onBrowser关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Google Chrome的扩展程序。我的后台脚本每次都在使用XMPP API的服务器上授权,并订阅PubSub节点。我需要在退出时取消订阅,否则虚拟订阅将保留在服务器上。 Google Chrome浏览器扩展程序API中是否存在 onBrowserClose 事件?

解决方案

Chrome扩展API中没有这样的事件。



然而有一个 chrome.windows.onRemoved 事件每次窗户关闭时都会发生火灾。我想你可以检查这个事件,如果你关闭了最后一个窗口,但不幸的是由于Chrome的异步性质,这是行不通的。



我试着运行一个简单的AJAX请求在 onRemoved 事件处理程序中。 AJAX请求永远不会到达服务器,因为Chrome在运行事件之前已经关闭了(或者只是忽略了它)。

做出最终答案为:否,目前你不能,据我所知。您可能希望在 http://crbug.com/30885 上发布以下错误报告,以获得关于更新的注意事项。

I am developing an extension for Google Chrome. My background script, everytime, authorizes on a server that uses the XMPP API, and subscribes for a PubSub node. I need to unsubscribe on the exit, otherwise the dummy subscriptions will remain on the server. Is There any onBrowserClose event in the Google Chrome Extension APIs?

解决方案

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.

这篇关于针对Google Chrome扩展程序的事件onBrowser关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆