本文介绍了以编程方式卸载/删除Firefox扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法来以编程方式卸载Firefox扩展。如果是的话 - 是否有可能从其他扩展中执行此脚本?解决方案
添加到使用
PERM_CAN_UNINSTALL
标志。
Addon.uninstall()
示例代码(您可能希望添加适当的错误处理,等等):
Components.utils.import(resource://gre/modules/AddonManager.jsm);
AddonManager.getAddonByID(some @ id,function(addon){
if(!addon){
//加载项不存在
return;
}
if(!(addon.permissions& AddonManager.PERM_CAN_UNINSTALL)){
//附加程序无法卸载
return;
}
addon.uninstall ();
if(addon.pendingOperations& AddonManager.PENDING_UNINSTALL){
//需要重新启动才能完成卸载
//可能要求用户这么做问,只是做
//或者等到用户重新启动浏览器
}
});
Is there a way to uninstall Firefox extension programmatically. If yes - Is it possible to execute this script from some other extension ?
解决方案
- Get a reference to the add-on using
AddonManager.getAddonByID
- Check that the add-on can be uninstalled (e.g. system-wide add-ons cannot be uninstalled by the user normally, but can be disabled), by checking the
PERM_CAN_UNINSTALL
flag. - Call
Addon.uninstall()
.
Example code (you might want to add proper error handling, and so on):
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID("some@id", function(addon) {
if (!addon) {
// Add-on not present
return;
}
if (!(addon.permissions & AddonManager.PERM_CAN_UNINSTALL)) {
// Add-on cannot be uninstalled
return;
}
addon.uninstall();
if (addon.pendingOperations & AddonManager.PENDING_UNINSTALL) {
// Need to restart to finish the uninstall.
// Might ask the user to do just that. Or not ask and just do.
// Or just wait until the browser is restarted by the user.
}
});
这篇关于以编程方式卸载/删除Firefox扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!