问题
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