2

So I'm working on a firefox extension that we'll be using internal (thus not terrible worried about security), and I'd like to be able to interact with the functions and values defined in the javascript of a webpage. I'm having trouble reliably finding variable definitions.

Take for example gmail, it has a VIEW_DATA list that has email subjects, etc to display. It can be accessed through window.content.frames.wrappedJSObject.VIEW_DATA, but this doesn't seem to always work for me.

Is there a reasonable way to reliably search (possible recursively) the javascript of a page for a given variable from a firefox extension?

2
  • for those wondering what |content.frames| could mean, it's the same as |content| (and |content.window|), actually: whatwg.org/specs/web-apps/current-work/multipage/… Commented Oct 29, 2009 at 8:58
  • So I tried it and VIEW_DATA is there, it's just null. I doubt you'll find it even if you found a way to search "all javascript". // As for finding, I haven't seen any such tools and I doubt you can scan all JS (including vars in the closures) without working on a low-level (debugger APIs or possibly even on SpiderMonkey level). That's just a guess though. Commented Oct 29, 2009 at 9:11

1 Answer 1

3

Is this what you are looking for?

var inspected = [];//prevent infinite loop; top===window

function inspector(obj) {
    inspected.push(obj);
    for(var prop in obj) {
        console.log(prop);
        if(!is_duplicate(obj) && typeof obj[prop] == 'object')
            inspector(obj[prop]);
    }
}

function is_duplicate(obj) {
    for(var i = 0; i < inspected.length; i++) {
        if(inspected[i] === obj)
            return true;
    }
    return false;
}

These functions will run through all of the properties of an object, walking all the way down the tree of objects. I just log the properties, but you may wish to do something more useful. Try inspector(window) and watch your firebug console get filled.

Sign up to request clarification or add additional context in comments.

1 Comment

To find text in DOM inspector(window) does not work. You can invoke inspector(document.getElementsByTagName('body')[0]) instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.