How can my Chrome plugin disable itself via Javasc

2020-08-03 04:59发布

问题:

My Chrome plugin requires the user to be logged in to a server to send back information for generating reports. I'd like to give the user the option to either log in or disable the plugin so that it will stop asking them to log in. How can I disable the a plugin via its own Javascript?

回答1:

chrome.management.setEnabled(chrome.i18n.getMessage("@@extension_id"), false);

You can't programmatically enable it after this, of course.



回答2:

Such action should be in the decision logic. Not so much disabling the script as just not doing anything. You could have a global flag or whatnot, but completely disabling the script is not the way to go, because it can't re-enable itself at that point.