我想知道当用户禁用/删除扩展时是否有一个动作触发器。
可能采取的行动:显示html页面类型:“我们不想看到您离开,请查看我们的网站”。
这样的东西能起作用吗?
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, {file: "myScript.js"});
});使用"myScript.js“保存要在单击时执行的逻辑。
取自这个职位
编辑:还找到“在禁用或卸载扩展名时没有事件会触发”
onUninstalled事件(来自API文档)在这里可能帮不了我吗?
发布于 2017-06-02 13:07:38
正如您在文档中看到的那样,browserAction.onClicked不能用于此任务。
由于扩展名中唯一能够禁用/删除它的部分是内容脚本,所以您可以声明一个内容脚本,该脚本定期尝试访问您的扩展,因此失败将指示该扩展被禁用。
下面是一个在所有打开的选项卡顶部显示DOM元素的示例:
manifest.json:
"content_scripts": [{
"matches": ["<all_urls>"],
"run_at": "document_start",
"all_frames": true,
"js": ["ping.js"]
}]ping.js:
var pingTimer = setInterval(ping, 1000);
function ping() {
var port = chrome.runtime.connect();
if (port) {
port.disconnect();
return;
}
clearInterval(pingTimer);
onDisabled();
}
function onDisabled() {
document.body.insertAdjacentHTML('beforeend',
'<div style="all:unset; position:fixed; left:0; top:0; right:0; height:2rem;' +
' background:blue; color:white; font: 1rem/2rem sans-serif; z-index:2147483647;">' +
'We hate to see you go. Please check our website: ' +
'<a style="all:inherit; color:cyan; display:inline; position:static;"' +
' href="http://example.com">http://example.com</a></div>');
}备注:
chrome.runtime幸存下来禁用了一个扩展。发布于 2017-11-03 06:44:39
嗨,你也可以用这个
chrome.runtime.setUninstallURL('http://myurl', function callback(id) {
console.log("successfully uninstall");
});
}https://stackoverflow.com/questions/44329086
复制相似问题