我发现这个地方和延伸甲是能够卸载延伸乙:Uninstall/Remove Firefox Extension programmatically?Firefox扩展可以自行卸载吗?
不知同样的方法也将工作延期卸载本身(例如,如果它检测上级扩展取而代之)?下面的代码是我的答案的简单适应上述链接的问题:
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID("[email protected]", function(betteraddon) {
if (betteraddon) {
AddonManager.getAddonById("[email protected]", function(thisaddon) {
if (!thisaddon) {
// this Add-on not present? Should not happen ...
return;
}
if (!(thisaddon.permissions & AddonManager.PERM_CAN_UNINSTALL)) {
// Add-on cannot be uninstalled
return;
}
thisaddon.uninstall();
if (thisaddon.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.
}
});
}
});
这听起来很危险的,因为自卸载插件至少从它自带的卸载返回到呼叫等待... 但是这种方法真的很危险吗?毕竟,现在卸载甚至可以撤销,这意味着卸载的插件“仍然存在”一段时间..?
这听起来像你的问题可以通过尝试它只是简单地回答。那么,当你尝试它时发生了什么? – Makyen
@Makyen当我在我自己的环境中在自己的机器上尝试一次时,某些工作可能会在不受我控制的情况下(例如竞争条件) –