I've done a lot of my own research but I'm really stuck here; could use some help.
Here is what I am calling from inside devtools.js
chrome.devtools.panels.elements.onSelectionChanged.addListener(function() { chrome.devtools.inspectedWindow.eval("$0", function (res) { port.postMessage(res);
});
But res evaluates to an error string: "Object has too long reference chain(must not be longer than 1000)"
From what I can tell from Googling, this is the way that one is supposed to get the selected element? This is the same behaviour in canary and the current user version of Chrome..
You can only request JSON-stringifyable objects. We can't pass live objects
across the contexts so we serialize them. So you need to process the result
within the eval and return a payload you can interpret on the call site
later.
On Tue, Nov 13, 2012 at 7:14 PM, Jason Mitcheson <ja...@pixeljet.net> wrote:
> I've done a lot of my own research but I'm really stuck here; could use
> some help.
> Here is what I am calling from inside devtools.js
> But res evaluates to an error string: "Object has too long reference
> chain(must not be longer than 1000)"
> From what I can tell from Googling, this is the way that one is supposed
> to get the selected element? This is the same behaviour in canary and the
> current user version of Chrome..
> But res evaluates to an error string: "Object has too long reference > chain(must not be longer than 1000)"
> From what I can tell from Googling, this is the way that one is supposed > to get the selected element? This is the same behaviour in canary and the > current user version of Chrome..
Is it possible *at all* to programatically access the '$0' element? It seems to only work when I actually evaluate it from the console. If I write a function to evaluate it, then it complains that it isn't defined. Here is a small test http://jsfiddle.net/JPeGT/. I have access both to the extension and the code running on the actual page.
> But res evaluates to an error string: "Object has too long reference > chain(must not be longer than 1000)"
> From what I can tell from Googling, this is the way that one is supposed > to get the selected element? This is the same behaviour in canary and the > current user version of Chrome..
Ok, I figured it out. $0 isn't in scope inside a function, but it's in scope if it's passed in as a parameter.. I can call this code from inside my devtools page
inside actual tab, running as user JS
function onSelectionChanged(element) { // element should be $0 / last selected element
}
inside devtools page
chrome.devtools.inspectedWindow.eval("window.qf.onSelectionChanged($0)", function (res) {
On Saturday, 17 November 2012 20:21:12 UTC+11, Jason Mitcheson wrote:
> I need some more help please.
> Is it possible *at all* to programatically access the '$0' element? It > seems to only work when I actually evaluate it from the console. If I write > a function to evaluate it, then it complains that it isn't defined. Here is > a small test http://jsfiddle.net/JPeGT/. I have access both to the > extension and the code running on the actual page.
>> But res evaluates to an error string: "Object has too long reference >> chain(must not be longer than 1000)"
>> From what I can tell from Googling, this is the way that one is supposed >> to get the selected element? This is the same behaviour in canary and the >> current user version of Chrome..