Chrome app, open link in a new tab

I am creating a chrome application that simply opens a link, for example, " http://www.cnn.com/ " on 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 also tried

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

and:

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

Help PLease.

thank

+4
source share
3 answers

Anyway, I tried window.openand it forked like a charm:

'use strict';

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

So it might work for you too.

+5
source

As with chrome 42, chrome.browser can help:

chrome.app.runtime.onLaunched.addListener(function() {
    chrome.browser.openTab({
      url: 'https://google.com/'
    });
});
+5
source

Link: https://developer.chrome.com/extensions/tabs#method-create

var options= { url: "http://cloudsupport.neonova.net/home" };

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.tabs.create(options);
});

then in manifest.json. add this permission.

...
"permissions": ["tabs","webview", "pointerLock", "geolocation", "videoCapture"]
...
-3
source

Source: https://habr.com/ru/post/1533654/


All Articles