How does a Firefox extension find itself when a user searches the search bar?

Is it possible for a Firefox extension to connect a search bar provided by a browser so that when a user executes a callback function (provided by an extension) it will accept a search request and which search engine to use?

I was able to find information about which XUL element contains the textbox in the search bar ( How do I target the search bar from a Firefox extension? ), But this is how far I could get it.

+3


source to share


1 answer


The searchbar element has a bunch of methods defined by the XBL file in chrome://browser/content/search/search.xml

. The function you are interested in will be doSearch(query, where, engine)

. A simple override seems to work:

// in the context of a loaded browser window…
let bar = document.getElementById("searchbar");
let doSearch = bar.doSearch;
bar.doSearch = function(query, where, engine) {
    // your code here! e.g. console.log(query, where, engine);
    // don't forget to call the original function:
    doSearch(query, where, engine);
};

      



An example is the Clear Search extension .

0


source







All Articles