Ok, here's the code I use to capture the page the user is currently
looking at:


// Get root.
var root = content.document.documentElement;

// Create path.
var path = this.getPref( "path", "string" );

// Create canvas.
var canvas = document.createElementNS( "http://www.w3.org/1999/
xhtml",
"html:canvas" );

// Get content.
var context = canvas.getContext( "2d" );

// Update file name.
name = name + ".png";

// Update path.
path = path + "\\" + name;

// Get document height.
var height = root.offsetHeight
| root.scrollHeight;

// Get document width.
var width = root.offsetWidth
| root.scrollWidth;

// Set canvas size.
canvas.height = height;
canvas.width = width;

// Set canvas size.
context.drawWindow( content,
0,
0,
canvas.height,
canvas.width,
"rgb(255,255,255)" );

// Create local file.
var image_loc = Components.classes [ '@mozilla.org/file/
local;1' ]
.createInstance( Components.interfaces.nsILocalFile );

// Set path.
image_loc.initWithPath( path );

// Create local URI.
var image_uri = makeFileURI( image_loc );

// Save contents.
internalSave( canvas.toDataURL( "image/png",
"quality=100" ),
null,
name,
null,
"image/png",
false,
null,
new AutoChosen( image_loc,
image_uri ),
null,
false );

// Success.
return( true );


If I do not use AutoChosen it works fine. But if I do try, I get the
following error in the console:


Error: uncaught exception: [Exception... "Component returned failure
code: 0x80004005 (NS_ERROR_FAILURE)
[nsIWebBrowserPersist.saveURI]" nsresult: "0x80004005
(NS_ERROR_FAILURE)" location: "JS frame ::
chrome://global/content/contentAreaUtils.js :: internalSave :: line
356" data: no]


Does anyone know how I can fix this?