Command: DOM Grabber #3

bard edited this page Sep 13, 2010 · 3 revisions

Grabs a XUL element on mouse click. Element under mouse is highlighted and reported in the title bar.


    repl> var res = repl.grab();
    repl> /* click an element in the browser... */
    repl> alert(;


function grab() {
    if(this._workContext instanceof Ci.nsIDOMWindow)
        var window = this._workContext;
        throw new Error('Not in a window.');

    var prevTitle =;
    var prevEl, prevColor;
    function onOver(event) {
        var curEl =; =
            '<' + curEl.nodeName + '> in ' + curEl.ownerDocument.location.href;

   = prevColor;

        prevEl = curEl;
        prevColor =; = '#E6E5C8';

    var repl = this;
    function onClick(event) {
        result.event = event;

    function finished() {
        window.document.removeEventListener('click', onClick, true);
        window.document.removeEventListener('mouseover', onOver, true); = prevColor; = prevTitle;

    var result = {};
    window.document.addEventListener('click', onClick, true);
    window.document.addEventListener('mouseover', onOver, true);
    return result;

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.