Search code examples
javascriptfirefoxmozillafirefox-addon-sdk

Add-ons SDK Mozilla Firefox currentURI


I work with a https://addons.mozilla.org/en-US/developers/builder (Add-ons builder) and I try to do the following things:

1.How to change currentURI address? Method setTabURL() is not suitable because immediately opens the URL.

While found a way out:

tab.attach ({
    contentScript: "history.pushState ('','', '" + tab.url + "');",
});

2.How to get the url address that is entered in the address bar? Method getTabURL() only shows the address at which settled.

3.How to add text to an icon in the toolbar? I use it here: https://builder.addons.mozilla.org/package/166563/


Solution

  • To access the URL bar and it's relate value you have to dig into the browser chrome a bit.

    This code snippet will get/set the URL bar value for the currently focused browser window:

    var wuntils = require('sdk/window/utils');
    var document = wuntils.getMostRecentBrowserWindow().document;
    // log the current URL bar value
    console.log(document.getElementById("urlbar").value);
    // change the current URL bar value (this won't change the page)
    document.getElementById("urlbar").value = "Thrift Shop";