Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript objects visible in FireBug, inaccessible in code

In my code I have a line that dumps the current window (which happens to be a youtube video page):

Firebug.Console.log(myWindow);

It can be seen that window object contains "yt" property, which is another object that can be easily inspected in debugger:

http://i.imgur.com/lHHns.png

Unfortunately, calling

 Firebug.Console.log(myWindow.yt);

logs "undefined" - why is that, and how can I access this "yt" property?

Edit: one addidtion that might be important: the code I'm writing is part of a firefox extension, so it's not really running inside a pgae, but in chrome - I'm starting to think that it may be the cause. Can chrome scripts be somehow limited in what they can see/acces as opposed to code in script tags?

like image 857
Kim Strauss Avatar asked Nov 04 '22 02:11

Kim Strauss


1 Answers

For security reasons, Firefox extensions don't access web page objects directly but via a wrapper. This wrapper allows you to use all properties defined by the DOM objects but anything added by page JavaScript will be invisible. You can access the original object:

Firebug.Console.log(XPCNativeWrapper.wrappedJSObject.yt);

However, if you want to interact with the web page from an extension you should consider alternatives where the web page cannot play tricks on you (e.g. running unprivileged code in the content window: myWindow.location.href = "javascript:...").

like image 103
Wladimir Palant Avatar answered Nov 09 '22 13:11

Wladimir Palant