javascript - Chrome Extensions: How to Manage separate instances of background pages? - Stack Overflow

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

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 puter. Doing this will allow me to test the extension as two different people yet on one puter. 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!

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 puter. Doing this will allow me to test the extension as two different people yet on one puter. 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!

Share Improve this question asked Jun 25, 2013 at 22:17 ansonanson 4,1742 gold badges24 silver badges30 bronze badges 2
  • Could you add the true reason for wanting two different background instances? This looks like a XY problem to, perhaps there's a better method than using two different instances (which is possible and quite easy to do though). – Rob W Commented Jun 25, 2013 at 23:07
  • The middle paragraph explains the exact reason why I need two different instances. Usually background pages exist once for all chrome windows. I can't mimic people on two different puters if both "people" (in this case, me) are connected to the same background page. – anson Commented Jun 25, 2013 at 23:19
Add a ment  | 

3 Answers 3

Reset to default 3

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/

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.

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745667014a4639180.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信