0

I am trying to find a 1-click solution to open multiple websites in different tabs in the same window in Google Chrome. I know that I can put all websites in a bookmarks folder and right click > open all (or middle click the bookmark folder), but that does not fit my needs.

To the best of my knowledge there is no way to launch multiple tabs using a non-user initiated javascript callback in Google Chrome. If that is the case, Chrome instead launches each website in a separate window as a pop-up (see here).

However, I managed to accomplish this task using a google Chrome App:

manifest.json

{
  "name": "Open multiple tabs",
  "version": "1.0",
  "description": "Opens multiple tabs in the same window.",
  "manifest_version": 2,
  "app": {
    "background": {
      "scripts": ["background.js"]
    }
  }
}

background.js

chrome.app.runtime.onLaunched.addListener(function() {
   window.open("http://plus.google.com");
   window.open("http://www.twitter.com");
   window.open("http://news.google.com/");
   window.open("http://bestofyoutube.com");
   window.open("http://www.sci2.tv/#!/browse");
});

Most probably there is something wrong with my code, since more than half of the times, after a tab is loaded it crashes, displaying the "Aw shap! Something went wrong while displaying this webpage. To continue, reload or go to another page" error message.

Also, Google+ (plus.google.com) always displays the message "You have been signed out of Google+" (if the tab does not first crash), which will not go away even after reloading.

It does not matter if I pack the App before installing it or not.

Any help would be greatly appreciated.

As a bonus, can someone please explain why replacing

window.open(url);

with

chrome.tabs.create(url);

results in the App doing absolutely nothing?

Thanks, Nikos

OSX Mavericks, Chrome Version 35.0.1916.153

Community
  • 1
  • 1
nikos
  • 147
  • 2
  • 9

1 Answers1

1

I think your problem is trying to create a Chrome App when the functionality you want is more suitable for an Extension. See here for a comparison between two.

As an example, what goes wrong with an App here?

  1. chrome.tabs API is unavailable for Apps. This is because apps are not supposed to:

    1. Interact with browser UI, i.e. open tabs in it;
    2. Have tabs inside themselves - they are supposed to look like "native" applications, not mini-browsers
  2. Google+ being signed out: this is because apps do not have access to the browser's own cookies. They have their own cookie store, and additional steps need to be taken to persist those.

So, what you really want is a Browser Action extension. It will present you with a nice button, and you can use chrome.windows and chrome.tabs to do what you want.

Xan
  • 74,770
  • 16
  • 179
  • 206
  • Thank you Xan for your answer, it is very helpful! I guess I am stupid I did not indicate in my question _why_ I need this functionality in the first place, in case someone thinks of a workaround to propose, and why an extension most probably does not fit my needs either: I am using the [ANTP](http://bit.ly/U6xq1r) extension, which allows the placement of a) links (which start with a valid protocol such as http://), b) Apps and c) ANTP widgets, in a tile grid within the new tab page. I want one of these tiles to launch multiple websites. Is there a way to launch an extension from javascript? – nikos Jun 17 '14 at 15:18
  • @Nicholas In that case, you want to create an ANTP _widget_, which is an extension that answers to external messages from ANTP. I can't find any documentation, but there are examples, for instance [here](https://github.com/NewTabPage). – Xan Jun 17 '14 at 15:23
  • I wanted to avoid that and have something more generic, but yes I guess that is the way to go! Thank you! – nikos Jun 17 '14 at 15:27
  • @Nicholas Seems like the ANTP project was abandoned in favor of Awesome HQ. I'm not 100% sure this approach will work. – Xan Jun 17 '14 at 15:34