admin管理员组

文章数量:1287147

I am building a chrome app, which will simply open a link, for example "/" 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('/', {

  });
});

I have also tried,

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create({ "url": "" });
});

as well as:

chrome.app.runtime.onLaunched.addListener(function(tab) {
  chrome.app.tab.create({ "url": "" });
});

PLease help.

Thank you

I am building a chrome app, which will simply open a link, for example "http://www.cnn./" 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./', {

  });
});

I have also tried,

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

as well as:

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

PLease help.

Thank you

Share Improve this question edited Mar 27, 2014 at 4:56 Derek 朕會功夫 94.4k45 gold badges197 silver badges253 bronze badges asked Mar 27, 2014 at 4:44 user3464774user3464774 631 silver badge3 bronze badges 5
  • Why are you building an app for just opening link? – Ale Commented Mar 27, 2014 at 4:50
  • you want page to open whenever chrome opens up? – Muhammad Umer Commented Mar 27, 2014 at 4:58
  • where is tab permission? shouldn't you have it – Muhammad Umer Commented Mar 27, 2014 at 4:58
  • ALso what is happening when you run this code – Muhammad Umer Commented Mar 27, 2014 at 5:02
  • @MuhammadUmer I want the page to open when I launch the app. I added the tab permission. When I double click on the app from Chrome:Apps , the page that is open "Chrome:Apps" closes and that's it. – user3464774 Commented Mar 27, 2014 at 12:05
Add a ment  | 

3 Answers 3

Reset to default 6

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

'use strict';

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

So it might work for you as well.

As of chrome 42, chrome.browser may help:

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

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

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

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

then in manifest.json. add this permission.

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

本文标签: javascriptChrome appopen link in a new tabStack Overflow