Chrome扩展程序在关机时的操作 [英] Chrome extension action on shutdown

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

问题描述

我正在编写一个非常简单的Chrome扩展程序,以自动清除我的历史记录,因为它不是内置功能.我已经将其功能化,但只想确认我在包装之前已经做了有意义的事情.

I'm writing a very simple Chrome extension to automatically clear my history as this isn't a built in feature. I've got it functional but just want to confirm I've done things that make sense before I wrap it up.

首先-是否有理由进行chrome.history.deleteAll?实际上,这似乎并未与URL浏览历史进行交互,相反,您需要为此使用chrome.browsingData.*.我还是应该做前者吗?

First - is there a reason to do a chrome.history.deleteAll? This doesn't actually appear to interface with URL browsing history, instead you need to use chrome.browsingData.* for that. Should I do the former anyway?

下一步-搜索之后,似乎无法在关闭时执行功能.我最接近这方面的真实信息的是某人说,当Chrome退出时,它会在不影响用户的情况下终止所有扩展.我是否缺少清除关机历史记录的方法?

Next - after searching and searching, there appears to be no way to execute a function on shutdown. The closest I got to real info on this was someone saying when Chrome quits it terminates all extensions without prejudice. Am I missing a way to clean up history on shutdown?

最后-由于无法在关机时进行清理,因此我在启动时使用后台页面中的window.onload进行清理. chrome.runtime.onStartup不能可靠地为我工作,而window.onload可以-这是做事的好方法吗?

Finally - as I can't cleanup on shutdown, I'm cleaning up on startup, using window.onload in the background page. chrome.runtime.onStartup did not reliably work for me while window.onload did - is this an okay way to do things?

在此先感谢您的帮助.

推荐答案

您是正确的,没有办法在Chrome关闭时执行任何操作. Chrome没有onClose事件.不仅从字面意义上,还是从隐喻上来讲:Chrome关闭时,它不会等待任何扩展程序关闭.

you are right, there's no way to execute anything on Chrome shutdown. Chrome doesn't have an onClose event. Not only literally, but metaphorically speaking: When Chrome closes, it doesn't wait for any extension to close.

您可以从chrome.windows.onRemoved挂起,等待最后一个窗口关闭,但是如果Chrome关闭,则不能保证扩展程序有时间运行它. onSuspend还是您发现的任何东西.

You can hang from chrome.windows.onRemoved and wait for the last window to close, but if Chrome is shutting down, it's not guaranteed your extension will have time to run it. Same thing with onSuspend, or whatever you find.

因此,如果您的实施可行,则不能保证它可以在其他Chrome上运行.

So, if your implementation works, it won't be guaranteed to work in other Chrome.

关于chrome.history.deleteAll,我也有同样的问题,将尝试使用chrome.browsingData,这是一种处理浏览数据(包括历史记录)的更现代,更完整的方法.

About chrome.history.deleteAll, I have the same problem, and will try with chrome.browsingData, a more modern and complete way to deal with browsing data, including history.

这篇关于Chrome扩展程序在关机时的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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