0
votes

I would like to save the HTML document in the current tab using a Firefox Add-on created with the Add-on SDK.

I'm trying like this:

exports.main = function() {

    require("widget").Widget({
            id: "foo",
            label: "My Test",
            contentURL: "http://www.mozilla.org/favicon.ico",
            onClick: function(event) {

                var {Cc, Ci} = require("chrome");
                var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
                var localPath = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
                localPath.initWithPath("/tmp/");
                var localFile = localPath.clone();
                localFile.append("mylocalfile.html");
                var tabs = require("tabs");
                persist.saveDocument(tabs.activeTab, localFile, localPath, null, 0, 0);
            }
    });
};

But the code above crashes Firefox (15.0) when I click on the widget.

I guess that tabs.activeTab might not be a nsIDOMDocument? Is that the problem?

How should I do to make it work?

1

1 Answers

1
votes

tabs.activeTab is definitely not an nsIDOMDocument, please see the docs here:

https://addons.mozilla.org/en-US/developers/docs/sdk/latest/packages/addon-kit/tabs.html

You should instead be able to simply open a tab via tabs.open, and attach content scripts to the opened tab. Here is an example of how to attach content scripts to an opened tab:

https://builder.addons.mozilla.org/package/22176/latest/