Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome app, open link in a new tab

I am building a chrome app, which will simply open a link, for example "http://www.cnn.com/" in a new tab in chrome.

I have the following code in my manifest.json

{
  "manifest_version": 2,
  "name": "CNN",
  "version": "2.1",
  "permissions": ["webview", "pointerLock", "geolocation", "videoCapture"],
  "app": {
    "background": {
      "scripts": ["main.js"]
    }
  }
}

And this is what i have in main.js:

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create('http://www.cnn.com/', {

  });
});

I have also tried,

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create({ "url": "http://cloudsupport.neonova.net/home" });
});

as well as:

chrome.app.runtime.onLaunched.addListener(function(tab) {
  chrome.app.tab.create({ "url": "http://cloudsupport.neonova.net/home" });
});

PLease help.

Thank you

like image 958
user3464774 Avatar asked Mar 27 '14 04:03

user3464774


2 Answers

Anyway, I've tried window.open and it forked like a charm:

'use strict';

chrome.app.runtime.onLaunched.addListener(function() {
    window.open("https://google.com/");
});

So it might work for you as well.

like image 83
Ale Avatar answered Oct 12 '22 23:10

Ale


As of chrome 42, chrome.browser may help:

chrome.app.runtime.onLaunched.addListener(function() {
    chrome.browser.openTab({
      url: 'https://google.com/'
    });
});
like image 33
Ivan Yan Avatar answered Oct 13 '22 01:10

Ivan Yan