nikos
nikos

Reputation: 147

Google chrome app to launch multiple tabs crashes unpredictably

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

Upvotes: 0

Views: 813

Answers (1)

Xan
Xan

Reputation: 77531

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.

Upvotes: 1

Related Questions