devhl
devhl

Reputation: 121

Open extension page in new tab

So I'm trying to make an extension that on click opens a tab and goes to a page. The only thing I can make it do so far is open a tab and give me this error:

No webpage was found for the web address: chrome-extension://hgjkkhjinhilcehaaldcnopaefinlfif/https://www.google.com/

Here is the manifest.json:

{
  "name": "New App",
  "version": "0.1",
  "permissions": ["tabs"],
   "manifest_version": 2,     
  "browser_action": {
   "default_icon": "icon.png"
  },
  "background": {
    "scripts": ["background.js"]
  },
  "icons": {
    "48": "icon.png"
  }
}

Here is background.js

chrome.browserAction.onClicked.addListener
    (function(tab) 
        {chrome.tabs.create({'url': chrome.extension.getURL('https://www.google.com/')}, function(tab) {})
        }                                    
    )

Upvotes: 1

Views: 1512

Answers (1)

devhl
devhl

Reputation: 121

What I was trying to do was open a new tab and go to a website in the browser action. Here is the answer:

Manifest.json

{ "name": "Funny Pictures",
  "version": "0.1",
  "manifest_version": 2, 
  "description": "Rick Roll all your friends!",
  "browser_action": {
        "default_icon": "funnyface.png"
  },
  "icons": {
            "48": "funnyface.png"
            },
    "background":{
                    "scripts": ["background.js"]
    }
}

background.js

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

    chrome.tabs.create({ url: newURL });
});

I swear I tried this previously, but that's how it goes I guess.

Upvotes: 1

Related Questions