Chrome extension: onclick extension icon, open popup.html in a new tab

I created the chrome extension and was able to open the popup.html file using window.open . however I want to open it in a new tab, I tried many different ways, including:

 <script type="text/javascript" language="JavaScript"> chrome.tabs.create('url': 'popup.html'); 

Am I just putting the code in the wrong place or am I not mistaken at all?

+17
google-chrome google-chrome-extension
Mar 09 '10 at 20:20
source share
3 answers

why do you want to open popup.html in a new tab? To do this, you need to create another page. In any case, if you want to open popup.html, in a new tab you will need to pass the extension URL.

http://code.google.com/chrome/extensions/extension.html#method-getURL

 chrome.tabs.create({'url': chrome.extension.getURL('popup.html')}, function(tab) { // Tab opened. }); 
+20
Mar 09 '10 at 23:40
source share

Now you can use Event Pages to open popup.html in a new tab when the extension button is clicked without creating a default_popup page.

manifest:

 "background": { "scripts": ["background.js"], "persistent": false } 

JS:

 chrome.browserAction.onClicked.addListener(function(tab) { chrome.tabs.create({'url': chrome.extension.getURL('popup.html'), 'selected': true}); }); 
+5
Jun 15 '15 at 5:29
source share

Use chrome.tabs.create (object properties, function callback) as described in http://code.google.com/chrome/extensions/tabs.html

Object properties may contain fields for windowId, index, url, and selected. The optional callback function gets the Tab object of the newly created tab.

So, the simplest example of creating a new tab in the current window and selecting it will look like this:

 chrome.tabs.create({'url': chrome.extension.getURL('popup.html'), 'highlighted': 'true'}); 

Not sure why you want to show popup.html in a new tab, but I find it very useful when developing / debugging my extension ... It's pretty painful that there is “usually” on the extension page, just a link to the help page.

I would like to know how to open it in a new window and, possibly, in kiosk mode; -)

+2
Mar 25 '10 at 16:27
source share



All Articles