I'm wondering if it's possible to have an action trigger when user disables/removes extension.
Possible actions: Show html page genre "We hate to see you go. Please check our website"
Would something like this work for this purpose ?
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, {file: "myScript.js"});
});
with "myScript.js" holding the logic to execute on click.
taken from this post
edit : also found "No event will fire in case an extension is disabled or uninstalled"
might the onUninstalled event (from the API docs) not help me out here?
As you can see in the documentation browserAction.onClicked cannot be used for this task.
Since the only part of an extension that survives disabling/removing it is a content script, you can declare a content script that periodically tries to access your extension so a failure would indicate the extension is disabled.
Here's an example that displays a DOM element on the top of all open tabs:
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>');
}
Notes:
chrome.runtime
survives disabling an extension, apparently. Hi You can also use this
chrome.runtime.setUninstallURL('http://myurl', function callback(id) {
console.log("successfully uninstall");
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.