Firefox, Plugins and Jetpack Widgets

Flash was chewing CPU in one of my myriad tabs, so I used Jetpack and the new AddonsManager API to whip up a quick add-on to enable and disable Flash quickly. It’s <30 lines of code and an image. It puts an icon in the Firefox 4 add-on bar that toggles the plug-in, and sends a Growl notification (or whatever system your OS uses) indicating that the plug-in was successfully enabled or disabled. Screenshot:

Install FlashToggle. Requires Firefox 4 beta 7 or newer.

Clone and make your own on the Add-on Builder. This might require a minor change in the code since I built using Jetpack 0.10, which isn’t released yet. Changing ‘contentURL’ to ‘image’ in the widget options should do the trick.

The entire code listing:

function toggleFlash(callback) {
  const { Cu } = require("chrome");
  Cu.import("resource://gre/modules/AddonManager.jsm", this);
  AddonManager.getAddonsByTypes(["plugin"], function(addons) {
    for (let i = 0; i < addons.length; i++) {
      if (addons[i].name == "Shockwave Flash") {
        addons[i].userDisabled = !addons[i].userDisabled;

let flashLogoURL = require("self").data.url("flash-logo.jpg");
  label: "Toggle Flash",
  contentURL: flashLogoURL,
  onClick: function() {
    toggleFlash(function(disabled) {
      let message = "Flash is now " + (disabled ? "disabled" : "enabled") + ".";
        title: message,
        iconURL: flashLogoURL

5 Comments on “Firefox, Plugins and Jetpack Widgets”

  1. Asa Dotzler says:

    Pretty awesome. The notification is anything but ambient though Also, maybe a Firefox bug but I can’t seem to move the button out of the add-on bar and into my primary toolbar. When I restart, it’s back in the add-ons bar again.

  2. Thomas says:

    Additionally the button messes up other button styles on Mac when moved to the navigation or tab toolbars (the bars get really narrow).
    And if the icon is the only one on the Addons bar, it interferes with the window resizer – I’m a bit surprised to see how buggy this (Addon bar and Addon SDK) still is. Now hoping to see these kinks being ironed out!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s