Skip to content Skip to sidebar Skip to footer

Getting The Contents Of The Toolbar Search Box Using The Mozilla Firefox Add-on Sdk

I am developing a Firefox addon and I was wondering how to get the contents of the search box in the toolbar using the Mozila Addon SDK? I finally found the chrome URL where it re

Solution 1:

Your "main" module (and other lib/ modules) do not have any document attached. You need to first use some low-level API such as the window/utils.getMostRecentBrowserWindow() function to obtain the DOMWindow for the active browser window. After that it's just getting the #searchbar element and checking the .value property (exposed through XBL).

Complete example:

const {getMostRecentBrowserWindow} = require("window/utils");

require("sdk/widget").Widget({
  id: "log-search-field",
  label: "Log Search Field",
  contentURL: "http://www.mozilla.org/favicon.ico",
  onClick: function() {
    let win = getMostRecentBrowserWindow();
    console.error("Search text: " + win.document.getElementById("searchbar").value);
  }
});

Post a Comment for "Getting The Contents Of The Toolbar Search Box Using The Mozilla Firefox Add-on Sdk"