Select a tab in Firefox from the command line

Firefox already allows you to open new URLs from the command line. Is there a way to select an existing tab from the command line, by title or URL?

+3


source to share


1 answer


Yes there is:



  • install MozRepl addon
  • run it: Tools -> MozRepl -> Start
  • use telnet to connect to your executable MozRepl instance:

    $ telnet 127.0.0.1 4242
    
          

    You can also use rlwrap

    to enable readline

    -like key bindings in telnet session:

    $ rlwrap telnet 127.0.0.1 4242
    
          

  • define a function to search for a tab with a given url and navigate to it. This from https://github.com/emacsmirror/cedet/blob/master/lisp/cedet/semantic/db-mozrepl.el is pretty cool:

    function semanticselecttab(url) {
         var numTabs=gBrowser.browsers.length;
         for(i=0; i<numTabs-1; i++) {
           if(gBrowser.browsers[i].contentDocument.location.href.indexOf(url)>=0) {
             gBrowser.tabContainer.selectedIndex=i;
             break;
           }
         }   
    }
    
          

  • execute it like this:

    repl> semanticselecttab("https://stackoverflow.com/questions/31055148/select-a-tab-in-firefox-from-command-line")
    
          

+2


source







All Articles