GitHunt
RU

ruediger/emacs-firefox-remote

Using Firefox' Remote Debugger from Emacs

-- mode:org; mode:auto-fill; fill-column:80; coding:utf-8; --

I just found out that a similar project which also includes Chrome support
exists: https://github.com/segv/jss


Since version 15 [[http://www.mozilla.org/firefox][Mozilla Firefox]] comes with a remote debugging protocol. This
was introduced to support debugging for Firefox on Android and FirefoxOS. But
it can also be activated for regular Firefox although it requires a bit of
extra work at the moment (Firefox 19).

This Emacs package provides a basic implementation of the protocol for Emacs.
So far only the lowlevel communication structure is done.

  • Configuring Firefox
    Go to =about:config= and set the following paramters:
    =devtools.debugger.remote-enabled= to =true= and =devtools.debugger.force-local=
    to =false= and =devtools.chrome.enabled= to =true= and restarted firefox.

Open a Scratchpad (Shift+F4 or WebDeveloper menu entry) and select in the
Environment menu the "Browser" option. Copy and paste the following script and
eval it with C-r.

#+BEGIN_SRC javascript
const Cu = Components.utils;

Cu.import("resource://gre/modules/devtools/dbg-server.jsm");

function startDebuggerServer()
{
// Start the server.
if (!DebuggerServer.initialized) {
DebuggerServer.init();
DebuggerServer.addBrowserActors();
}
// For an nsIServerSocket we do this:
DebuggerServer.openListener(6000); // A connection on port 6000.
}

startDebuggerServer();
#+END_SRC

  • Information
  • Basic Usage

#+BEGIN_SRC emacs-lisp
(let ((con (firefox-remote-connect "localhost" 6000)))
(firefox-remote-send con '((to . root) (type . listTabs))
(lambda (data)
(let* ((selected (cdr (assq 'selected data)))
(tabs (cdr (assq 'tabs data)))
(current-tab (aref tabs selected))
(url (cdr (assq 'url current-tab)))
(title (cdr (assq 'title current-tab))))
(message "Current Tab "%s": "%s"" title url))))
(sleep-for 10)
(firefox-remote-disconnect con))
#+END_SRC

This should print the title and url of the currently selected tab to the
=Messages= buffer.

Languages

Emacs Lisp100.0%

Contributors

Created March 19, 2013
Updated July 14, 2022
ruediger/emacs-firefox-remote | GitHunt