Reputation: 7156
I am making a Chrome extension with a "default_popup":"popup.html"
.
Documentation of chrome.browserAction.onClicked
says:
Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup.
I know browserAction.onClicked
will not fire in my extension. But can i disable popup so that browserAction.onClicked
can fire?
Conclusion : While my extension is running, I want to disable popup
and have a chrome.browserAction.onClicked
in my background.js
so that later some time I can call browserAction.onClicked
. Is it possible? How? Also I would like to know If I can do the reverse meaning disable browserAction.onClicked
and enable popup
.
Upvotes: 3
Views: 852
Reputation: 77502
You can disable the popup (automatically enabling the dispatch of onClicked
events) by setting the popup path to an empty string:
chrome.browserAction.setPopup({popup: ""});
Likewise, you can enable the popup afterwards by providing a valid path:
chrome.browserAction.setPopup({popup: "popup.html"});
You can keep a listener to onClicked
regardless - it's just that the event is not always dispatched.
Please note: you can't have the popup disabled, capture the click and then show the popup - you can only change what happens at next click. If you want both a popup and some event in the background, it's best to simply message background from the popup.
Upvotes: 6