Chrome extension browser action event not firing

非 Y 不嫁゛ 提交于 2021-01-27 06:35:02

问题


I want to make chrome extension which opens all my favourite websites when I click on it.

Currently my manifest.json is:

{
  "manifest_version": 2,
  "name": "Soical_open",
  "description": "This extension opens all my favorite social sites once",
  "version": "1.0",
  "background": {
    "scripts": ["background.js"]
  }
}

and my background.js is:

var queue = ['www.fb.com', 'www.gmail.com' , 'www.quora.com'];
chrome.browserAction.onClicked.addListener(function(tab) {
  for (var i=0; i<queue[1].length; ++i)
    chrome.tabs.create({"url": queue[i], "active": false, "index":tab.index+i});
});

When I load this extension and click on it, nothing happens. What is that I am doing wrong? What am I missing?


回答1:


You did not create a Browser Action.

It's messy since Chrome introduced mandatory icons in toolbar for all extensions, but if you don't declare a "browser_action" section in the manifest, that dummy "button" doesn't fire any event. Clicking it just opens a context menu.

Just supply an icon and add a "browser_action" section to the manifest, and it will work (do not specify a popup, just the icon/title, otherwise onClicked will not fire).



来源:https://stackoverflow.com/questions/37143377/chrome-extension-browser-action-event-not-firing

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