Q:

How to deal with getImageData at bounds in Firefox? 

I'm currently writing a little drawing application that needs to access pixel data for its smudge and blur tools and bumped into a nasty issue with HTML5 Canvas API in Firefox.  Apparently it does not implement getImageData quite as defined in the spec.  The spec specifically says "... Pixels outside the canvas must be returned as transparent black. ...". 
This doesn't happen in FF (tested in FF 3.6 and 4 beta 9).  Instead it will give an error such as this: An invalid or illegal string was specified" code: "12
Note that this appears to work in Chrome just fine.  
I guess this means I will have to implement some extra code to work around this limitation.   I managed to bypass the issue using the following code:
            getImageDataAround: function(p, r) {
                p = this._toAbsolute(p);
                r = this._toAbsolute(r);

                p = p.sub(r);

                var d = r * 2;
                var width = d;
                var height = d;

                // XXX: FF hack
                if(navigator.userAgent.indexOf('Firefox') ! = -1) {
                    if(p.x < 0) {
                        width += p.x;
                        p.x = 0;
                    }

                    if(p.y < 0) {
                        height += p.y;
                        p.y = 0;
                    }

                    var x2 = p.x + width;
                    if(x2 >= this.width) {
                        width = d - (x2 - this.width);
                    }

                    var y2 = p.y + height;
                    if(y2 >= this.height) {
                        height = d - (y2 - this.height);
                    }

                    if((width ! = d) || (height ! = d)) {
                        // XXX: not ideal but at least this won't give any
                        // errors
                        return this.ctx.createImageData(d, d);
                    }
                }

                return this.ctx.getImageData(p.x, p.y, width, height);
            },

This isn't cool since I return bunch of empty pixels to the caller.  It would be way nicer to return results just like in the spec. 
Just to clarify the code is a part of a Context API that wraps real context and provides some extra functionality (relative coords etc.).  That probably explains where things like this.width etc.  come from. 
It's the XXX part that's troublesome.  I simply need some way to return ImageData that's up to spec.  Any ideas on how to do this are welcome. :) 

A:

Perhaps you could create a canvas of size d by d and draw the appropriate portion of the original canvas on to it?  Sadly you can't draw the original canvas directly because you run into the same sort of bounds-checking code, so you have to figure out the overlap. 
You should consider sniffing for Gecko rather than Firefox. 
By the way, this is Mozilla bug 392751.