views:

139

answers:

1

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?

+1  A: 

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.

geowa4