anson
anson

Reputation: 4164

Chrome Extensions: How to Manage separate instances of background pages?

Does anyone know of a way to get each separate Chrome Window to run a different background page instance?

Currently, my problem is that I need to open two chrome windows and have each background page be its own separate instance. This "mimics" the act of two separate users using the extension on their own computer. Doing this will allow me to test the extension as two different people yet on one computer. Right now, when I open two Chrome Windows, it uses the one background page instance (as I suppose it should).

I guess any acceptable method would be great, whether that is some form of multiple Chrome sign-ins or installing different instances of chrome. The best solution however would be code based, in the realm of the actual Chrome Extension API, if it allows.

Thanks!

Upvotes: 2

Views: 4670

Answers (3)

anson
anson

Reputation: 4164

After some time I solved my problem fairly easily. It requires you to have two Google accounts. So if you do not have two accounts and do not want two accounts, it may be best to use Rob W's answer on this post...

Steps:

  • Open up a Chrome window.
  • Click the settings drop down -> then click settings
  • Under the Users heading, click add new user
  • You may be prompted to sign in using a Google account, do so
  • Open up a second window, repeat process and assign the second user to the current window
  • Now you should have two windows, under two different users. Both use their own settings and their own extensions, along with their own background pages.

Upvotes: 1

Rob W
Rob W

Reputation: 348992

The only way to have two instances of a background page is to enable split incognito behaviour, and open an incognito window (Ctrl + Shift + N).

To enable split incognito mode, add the following to your manifest file:

"split": "incognito"

If you really want to simulate two or more users, use different data directories, by starting Chrome with the --user-data-dir flag. For example:

chromium --user-data-dir=/tmp/whatever/

Upvotes: 3

AntonNiklasson
AntonNiklasson

Reputation: 1749

Maybe you could instantiate some "background page object" in the one background page for each open window? Put all your functionality in that class and create some array with all the instances in it.

Just some brainstorming, hope it gets you somewhere.

Upvotes: 0

Related Questions