5

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.)

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mouse
  • 51
  • 3
  • 4
    Happy that you found a solution that worked! You should post your answer to your question in the form of an answer below. Then accept it as an answer. This way the question will appear as answered. – Gibron Jan 12 '13 at 04:00
  • @Rizier123 Please take great care when removing solutions from questions. Yes, this is bad that people do it. It's worse when you delete something and don't leave it elsewhere. It's not guaranteed that the author will react and put it back in, unlikely even. The correct way is to appeal to the user (which was done in '13!) and if that doesn't work - make a community wiki with what you're removing. In this particular case it's a clear-cut duplicate and I have dealt with it as such. I see you're currently doing a lot of such edits - please keep the above in mind and do not erase information. – Xan Mar 04 '16 at 13:23
  • @Xan I will keep it in mind from now on. I always leave a edit summary comment about it. Thanks for the notice. – Rizier123 Mar 04 '16 at 13:25

0 Answers0