0

I am trying to create a little chrome extension with a toggleable icon ("active" and "inactive") and a pupup-page. The icon should be active, when the popup is shown and inactive, when the popup is hidden. I am allready able to toggle the Icon on click using the background-script, just like in this answer.
But unfortunately this doesn't work, if you have a default_popup-page, as the browser_action catches the clickEvent and the background-script does not get notified.
So my question is, how can i toggle the icon while using a default_popup-page?

EDIT: The problem i have is, that the chrome.browserAction.onClicked method is not called, when you have a default_popup (it is also said in the comments to this answer). So i need something else to get notified, if the extension was clicked or not...

Community
  • 1
  • 1
Robert P
  • 9,398
  • 10
  • 58
  • 100
  • Show your code, so far it seems you did something wrong because there are no such restrictions on changing the icon. – wOxxOm Nov 18 '15 at 10:44
  • @wOxxOm the problem is not changing the icon, but the `clickEvent`. As described [in the comments of this answer](http://stackoverflow.com/a/15195401/3182091), the `chrome.browserAction.onClicked` is not fired, when a `default_popup` exists... – Robert P Nov 18 '15 at 10:49
  • Ah, I see! Then what about simply changing the icon in the popup script on start and change it back in `onbeforeunload`? – wOxxOm Nov 18 '15 at 10:51
  • `onbeforeunload`? Never heard about that, but it sounds like a possible solution. I am still new to extension development so i did not know about that. I'll try that soon. Thanks! – Robert P Nov 18 '15 at 10:55
  • @wOxxOm tryed it yesterday and it worked with `unload`. Basicly i made a function `toggle` inside the `background.js` and called it, when the `popup.html` has been loaded. Also i add a `EventListener` for "unload"` to the `popup.js`, which calls `toggle` for the `background.js`. Unfortunately, i have seen, that the popup closes, when it looses focus, so i can't really use it for my case. But thats a different story. Please write an answer to this question so i can mark it as accepted. – Robert P Nov 19 '15 at 07:00
  • My idea was different and nonworking because Chrome apparently doesn't call `window.onbeforeunload` in the popups. – wOxxOm Nov 19 '15 at 11:01
  • @wOxxOm yea, i saw that, while searching for the documentation of `onbeforeunload` and there i also found the solution using `unload` instead. – Robert P Nov 19 '15 at 13:05

0 Answers0