http://jsfiddle.net/sLk72mud/
Inn the jsfiddle, the call to measureText that sets the canvas width:
tCtx.canvas.width = tCtx.measureText(this.value).wi