Chrome Browser Action Popup and icon switch does not work

拜拜、爱过 提交于 2019-12-17 21:28:52

问题


While using a default popup for my Chrome extension, I can't change the icon for the state of the extension. If I disable the popup.html the state changing icons are working. I used a toggle method for changing the icons, which worked perfectly before without using the popup.html. How is that possible? Can anyone help me please?

thanks in advance!


回答1:


When you have a popup set, chrome.browserAction.onClicked is not fired.

You will need to message your extension's background page from the popup to inform it about the click, e.g.:

// background script
chrome.runtime.onMessage.addListener( function (message, sender, sendResponse) {
  if (message.clicked) {
    /* Do the usual onClicked stuff */
  }
});

// popup script
chrome.runtime.sendMessage({clicked : true});


来源:https://stackoverflow.com/questions/23316974/chrome-browser-action-popup-and-icon-switch-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!