title: Enable/disable Chrome plugin from extension
body: <p>Is it possible to enable/disable a Chrome plugin from an extension?</p>
  <p>My end goal is to write an extension that, for some specific plugin (in my case Flash), gives a one-click way to do the equivalent of going to <code>chrome://plugins</code>, finding the relevant plugin on the list, and clicking &quot;enable&quot; or &quot;disable.&quot;</p>
  <h1>Update 2</h1>
  <p>I have found that it <em><strong>is</strong></em> possible to achieve the desired result by entering the code  below into the JavaScript console on <code>chrome://plugins</code>. Now the <strong>question</strong> is how to do this in one click with an extension or bookmarklet. I'm keeping (a shortened form of) &quot;update 1&quot; after the code to show how I arrived at it.</p>
  <p>To turn Flash <strong>OFF</strong>: <code>chrome.send('enablePlugin', ['/Applications/Google Chrome.app/Contents/Versions/37.0.2062.94/Google Chrome Framework.framework/Internet Plug-Ins/PepperFlash/PepperFlashPlayer.plugin', String(false), String(false)]);</code></p>
  <p>To turn Flash <strong>ON</strong>: <code>chrome.send('enablePlugin', ['/Applications/Google Chrome.app/Contents/Versions/37.0.2062.94/Google Chrome Framework.framework/Internet Plug-Ins/PepperFlash/PepperFlashPlayer.plugin', String(true), String(false)]);</code></p>
  <h1>Update 1</h1>
  <p>On the <code>chrome://plugins</code> page, there are event handlers in <code>plugins.js</code> that listen for clicks on the &quot;enable&quot; or &quot;disable&quot; links. Here's lines 123-139:</p>
  <pre><code>renderTemplate(pluginsData);
  
  // Add handlers to dynamically created HTML elements.
  var links = document.getElementsByClassName('disable-plugin-link');
  for (var i = 0; i &lt; links.length; i++) {
    links[i].onclick = function() {
      handleEnablePlugin(this, false, false);
      return false;
    };
  }
  links = document.getElementsByClassName('enable-plugin-link');
  for (var i = 0; i &lt; links.length; i++) {
    links[i].onclick = function() {
      handleEnablePlugin(this, true, false);
      return false;
    };
  }
  </code></pre>
  <p>So this basically passes inputs to a universal plugin on/off function, which is in lines 192-203:</p>
  <pre><code>/**
   * Handles a 'enable' or 'disable' button getting clicked.
   * @param {HTMLElement} node The HTML element for the plugin being changed.
   * @param {boolean} enable Whether to enable or disable the plugin.
   * @param {boolean} isGroup True if we're enabling/disabling a plugin group,
   *     rather than a single plugin.
   */
  function handleEnablePlugin(node, enable, isGroup) {
    // Tell the C++ PluginsDOMHandler to enable/disable the plugin.
    chrome.send('enablePlugin', [String(node.path), String(enable),
                String(isGroup)]);
  }
  </code></pre>
  <p>Thanks to Developer Tools/&quot;Inspect Element&quot;, it's clear what inputs to send to the function — <code>node.path</code> would be something like <code>/Applications/Google Chrome.app/Contents/Versions/34.0.1847.137/Google Chrome Framework.framework/Internet Plug-Ins/PepperFlash/PepperFlashPlayer.plugin</code>.</p>