I would like to trigger the save of a page's content from within the
browser session and thought that using nsIWebBrowserPersist
saveDocument to accomplish this. My test case is a simple html page
with an onload function named on the body (see below).

During the call to saveDocument I am receiving the error "uncaught
exception: [Exception... "Component returned failure code: 0x80004005
(NS_ERROR_FAILURE) [nsIWebBrowserPersist.saveDocument]"  nsresult:
"0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: file:///<path
to file removed>/trysave.html :: trysave :: line 19"  data: no]"

Unfortunately NS_ERROR_FAILURE seems to be a very generic error.

Is what I am attempting actually permissible and if so does anyone
have an idea what I might be doing wrong.

Thanks in advance,

Pete


HTML Source
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Title</title>
<script type="text/javascript">
function trysave() {
        netscape.security.PrivilegeManager.enablePrivilege
('UniversalXPConnect');
        with(Components.interfaces) {
                var Cc = Components.classes;
                var file = Cc["@mozilla.org/file/local;1"].createInstance
(nsILocalFile);
                file.initWithPath("~/trysave.html");
                var dataPath = Cc["@mozilla.org/file/local;1"].createInstance
(nsILocalFile);
                file.initWithPath("~/trysave");
                var wbp = 
Cc['@mozilla.org/embedding/browser/nsWebBrowserPersist;1']
                   .createInstance(nsIWebBrowserPersist);
                const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
                wbp.persistFlags = nsIWBP.PERSIST_FLAGS_FROM_CACHE |
nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION |
nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
nsIWBP.PERSIST_FLAGS_NO_BASE_TAG_MODIFICATIONS |
nsIWBP.PERSIST_FLAGS_DONT_FIXUP_LINKS;
                var encodingFlags = nsIWBP.ENCODE_FLAGS_RAW |
nsIWBP.ENCODE_FLAGS_ENCODE_W3C_ENTITIES;
                wbp.saveDocument(document, file, null, null, 0, 0);
        }
}
</script>
</head>
<body  onload="trysave();">
now is the time for all good men to come to the aid of their country!
</body>
</html>
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to