Snippets code from my daily experience

January 12, 2010

Porting Table2Clipboard to Jetpack

Filed under: jetpack,table2clipboard — dafi @ 7:54 pm

I’ve written many Jepacks to solve little annoying problems mainly related to urls and tabs.

JetColorTab, the 50 Line code contest’s winner born to solve a need without installing full features extensions.

In these days the Mozilla community (and me) has debated about the future of Jetpack and XUL and many people says “a big number of extensions can be written simply using standard DOM and HTML”

This sentence intrigued me so I’ve tried to rewrite Table2Clipboard (T2C) for Jetpack, T2C makes a simple operation, it copies HTML selection also DOMRange to clipboard preserving the format and many other aspects.

After 30 minutes the porting was completed (excluding the UI not yet rewritten) so heavily DOM oriented extensions can be easily ported to Jetpack but some XUL code remains.

Extensions like NoScript or AdBlockPlus today are very hard (impossible??) to move to Jetpack and hopefully this is not necessary because XUL sits near to us for a long time :)

Little fixes to T2C required

  • Jetpack version 0.6.2 doesn’t allow (or at least I’m not able) to use modules so while waiting for CommonJS comes to Jetpack it is necessary to copy all scripts into the main jetpack file
  • HTMLTableElement, HTMLTableCellElement, HTMLTableRowElement are not “visible” so expressions like
    if (a instanceof HTMLTableElement) {}

    don’t work but this isn’t a problem because the code can be written more efficiently

    if (a.localName == "TABLE") {}
  • can be replaced by the standard Jetpack context.node, the parameter context is passed for example to beforeShow()

Where XUL is necessary and improvements required

  • Jetpack allows to obtain the text or HTML selection using jetpack.selection but it doesn’t expose the focusNode so I used jetpack.tabs.focused.contentWindow.getSelection() (i.e. XUL nsISelection)
  • XUL clipboard supports flavors but under Jetpack you can set only one at time, so you can’t add text version plus html version of same content, I think the ‘set’ method should have an ‘add’ mate
  • T2C needs to access to CSS using ownerDocument.defaultView.getComputedStyle
  • T2C uses the inIDOMUtils, it should be great if this interface become available from Jetpack

Jetpack Table2Clipboard can be downloaded from the Jetpack Gallery

About these ads


  1. fyi: (a.localName == “TABLE”) will never be true in Gecko 1.9.2+. Instead, localName returns “table”. See

    Comment by Ms2ger — January 12, 2010 @ 8:55 pm

  2. Nice test dear Davide :) But note the user is missing a localizable user-friendly interface that was present in the xul extension ;-)

    Comment by Goofy — January 13, 2010 @ 7:33 pm

    • Sure, I hope very soon Jetpack will give to developers a localization environment as mentioned into JEP 35

      Comment by dafi — January 13, 2010 @ 7:37 pm

RSS feed for comments on this post.

The Rubric Theme. Blog at


Get every new post delivered to your Inbox.

%d bloggers like this: