How to enable or disable google chrome extensions through the console

Today, opening Google Chrome, I realized that there is no easy way to enable or disable the extension without going to one of the following places:

  • chrome: // extensions
  • clicking on Tools> Extensions> Enable / Disable

The reason this is so important is due to the resources it uses.

For example: I started my computer and I immediately want to quickly open Google Chrome. Say, for example, that before starting Chrome, I start 100 processes. However, as soon as I open Chrome, this number jumps to 160 because of all the extensions that load when it starts.

Here is what I am looking for to achieve and current limitations:

Desired Result: Easily Enable / Disable / Uninstall Extension Using Console

Limitations: It is not possible to group many extensions so that they can be easily turned on / off.

Please let me know if this part of the question is not resolved / disabled.

+7
source share
1 answer

Chrome saves the extension settings in a JSON file named "Preferences" in your profile directory (here it is ~ / .config / google-chrome / Default / Preferences). The enabled / disabled flag is a β€œstate” for each extension, with 1 for enabled and 0 for disabled. You can write a script that modified this file before launching Chrome. You can set this script to run on login, and even to launch Chrome at the end if you want Chrome to start automatically. Save the list of extensions that you want to explicitly disable before starting to select only a few.

I'm sure you are not updating the settings while Chrome is running.

This works for me and will probably work on any * nix-like system. Porting to Windows should be simple enough: chrome_dir and checking whether Chrome works or not may be the only changes.

#!/usr/bin/env python2.6 import datetime import json import os import sys from os import path chrome_dir = path.expanduser("~/.config/google-chrome") if path.lexists(chrome_dir + "/SingletonLock"): # there may be a better and portable way to determine if chrome is running sys.exit("chrome already running") prefs_file = chrome_dir + "/Default/Preferences" now = datetime.datetime.now() prefs_backup_file = prefs_file + now.strftime("-%Y%m%d-%H%M%S") enable_keys = [ # list hash keys, you can find from URL given on chrome://extensions "aeoigbhkilbllfomkmmilbfochhlgdmh", ] disable_keys = [ "hash-like key here", ] default_state = 0 # 1 to enable, 0 to disable, None to leave alone with open(prefs_file) as f: prefs = json.load(f) os.rename(prefs_file, prefs_backup_file) for key, ext in prefs["extensions"]["settings"].iteritems(): if not ext.has_key("state"): # may be blacklisted continue if key in enable_keys: ext["state"] = 1 elif key in disable_keys: ext["state"] = 0 elif default_state is not None: ext["state"] = default_state with open(prefs_file, "w") as f: json.dump(prefs, f) 
+11
source

All Articles