Google Chrome Extensions - open a new tab when you click the toolbar icon

How to create a Chrome extension that adds an icon to the toolbar, and when you click on it, a new tab opens with some local web page (for example, f.html)?

I saw this question , but it doesn’t actually explain what I should add to the manifest file ...

+67
html google-chrome google-chrome-extension
Jul 06 2018-10-06T00:
source share
3 answers

This does not apply to newer Chrome apps.

Newer Chrome apps with manifest_version: 2 require tabs to open as:




chrome.browserAction.onClicked.addListener(function(activeTab) { var newURL = "http://www.youtube.com/watch?v=oHg5SJYRHA0"; chrome.tabs.create({ url: newURL }); }); 



+91
Feb 04 '13 at 8:06
source share

Well, in the docs extensions , manifest says, you'll need to include β€œtabs” as your permission. Similarly, they explain the welcome global application:

Manifest file:

 { "name": "My Extension", "version": "1.0", "description": "Opens up a local webpage", "icons": { "128": "icon_128.png" }, "background_page": "bg.html", "browser_action": { "default_title": "", "default_icon": "icon_19.png" }, "permissions": [ "tabs" ], } 

In the background page, you listen for a mouse click event in a browser action.

 chrome.browserAction.onClicked.addListener(function(tab) { chrome.tabs.create({'url': chrome.extension.getURL('f.html')}, function(tab) { // Tab opened. }); }); 

As you noted above, you will see that I used the question that you saw in another post. Please note that this is not verified, but I believe that it should work.

+51
Jul 06 '10 at 18:58
source share

chrome.tabs.create needs permission of "tabs".

Just using window.open in the extension without any permissions. and the code is shorter. I suggest this solution.

 window.open(url,'_blank'); 
+4
Feb 07 '15 at 8:57
source share



All Articles