Create new tab from browserAction in Chrome

1k Views Asked by At

Update: Found a solution in another one; apparently I miscopied it before! This worked:

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

Source: Google Chrome Extensions - Open New Tab when clicking a toolbar icon


I am trying to create a new tab and set it to background.html upon clicking the BrowserAction button, but nothing happens when I click.

(This is a precursor to making a sort of apish imitation of a sidebar for bookmarks, since there is no sidebar available.)


manifest.json

{
    "name": "Bookmarks Bar",    
    "permissions": 
        [
            "bookmarks",
            "tabs"
        ],
    "version": "0.0",
    "manifest_version": 2,
    "description": "A bookmarks sidebar for Chrome.",

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

    "browser_action":
        {
            "default_icon": "icon.png",
            "default_title": "Bookmarks Sidebar"
        }
}

background.js

// Called on browser_action click.
chrome.browserAction.onClicked.addListener(function(tabs.Tab tab) 
    {
        chrome.tabs.create({"url": chrome.extension.getURL("background.html"), "selected": true});
    });

The background.html page is currently just a dummy page with some text. No errors are showing up when I try to add this to Chrome (not that this means much).

I've looked at some other, similar questions on here, but the results I found have led me to this... still stuck, and not working. Thank you for any help and please let me know if I need to clarify anything further.

(I apologize for the noobish question, but it's been years since I worked with javascript, and this is my first attempt at a Chrome extension.)

0

There are 0 best solutions below