0

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 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.