Viewing global variables?

1,668 views
Skip to first unread message

Woody

unread,
Jan 7, 2011, 1:52:37 PM1/7/11
to Firebug
Firebug seems to show all variables that are in scope, but what if I
want to know the value of a global variable. A related Q: how can I
look at the value of a variable in another frame (not the one
containing the script under execution)?

Sergio Cinos

unread,
Jan 7, 2011, 1:54:58 PM1/7/11
to fir...@googlegroups.com
Global variables: inspect window
Variables from an iframe: inspect <iframeElement>.documentWindow
Variables from your parent frame: inspect window.parent

--
S.Cinos
JavaScript Developer at Tuenti.com

2011/1/7 Woody <ols...@sbcglobal.net>:

> --
> You received this message because you are subscribed to the Google Groups "Firebug" group.
> To post to this group, send email to fir...@googlegroups.com.
> To unsubscribe from this group, send email to firebug+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/firebug?hl=en.
>
>

Woody

unread,
Jan 7, 2011, 5:11:05 PM1/7/11
to Firebug
On Jan 7, 10:54 am, Sergio Cinos <sergio.ci...@gmail.com> wrote:
> Global variables: inspect window
> Variables from an iframe: inspect <iframeElement>.documentWindow
> Variables from your parent frame: inspect window.parent

I don't understand what you mean. There is no "inspect" panel, and
typing "inspect window" in as a console command line gives an error. I
can find nothing in the documentation about "inspect".

If you can explain more fully, I can add it to the documentation.

Sergio Cinos

unread,
Jan 7, 2011, 5:22:15 PM1/7/11
to fir...@googlegroups.com
Sorry, I don't have Firebug installed in this computer. If I recall
correctly, there is to ways to 'inspect' or see the value of a
variable:

a) Executing 'console.dir(window.parent)'. The variable content will
be printed in the Console panel
b) Adding 'window.parent' as a new Watch expression in the Script panel.

My main point is: Firebug doesn't need to provide a special way to
inspect global variables or iframe variables, as you can view their
values using 'window', 'window.parent', etc.

--
S.Cinos
JavaScript Developer at Tuenti.com

2011/1/7 Woody <ols...@sbcglobal.net>:

John J Barton

unread,
Jan 7, 2011, 6:18:09 PM1/7/11
to Firebug
the DOM or Document Object Model panel shows the global window object.
The command line has a dir(object) and cd(window) commands

http://getfirebug.com/wiki/index.php/Command_Line_API#cd.28window.29

jjb

Woody

unread,
Jan 7, 2011, 6:37:26 PM1/7/11
to Firebug
On Jan 7, 10:54 am, Sergio Cinos <sergio.ci...@gmail.com> wrote:
> Global variables: inspect window
> Variables from an iframe: inspect <iframeElement>.documentWindow
> Variables from your parent frame: inspect window.parent

Woody

unread,
Jan 8, 2011, 1:40:59 AM1/8/11
to Firebug
Sorry, I don't understand either of your answers. Adding window.parent
as a new Watch expression shows all the properties of the window, but
not any of the global variables. Typing dir(parent) or dir(window) in
the DOM command line gives "ReferenceError: dir is not defined
{ message="dir is not defined", lineNumber=1, more...}".

In any case, even if these methods worked, they are far too cumbersome
to be useful. What is needed is for the global variables to appear
automatically in the Watch window, or at least an object that expands
to showing the global objects.

Here is a sample HTML page with some global variables gn and gs. Can
you give me step-by-step directions for viewing their values if I am
at a Javascript breakpoint in frame L?

<html>
<head>
<title>My Page</title>
<script>
var gn;
var gs=[];
</script>
</head>
<frameset rows="400,*">
<frameset cols="400,*">
<frame src="B.html">
<frame src="S.html">
</frameset>
<frameset cols="550">
<frame src="L.html">
</frameset>
<noframes>
You need to have a more current browser to use this player.
</noframes>
</frameset>
</html>

Woody

unread,
Jan 8, 2011, 1:42:15 AM1/8/11
to Firebug

John J Barton

unread,
Jan 8, 2011, 12:05:04 PM1/8/11
to Firebug


On Jan 7, 10:40 pm, Woody <ols6...@sbcglobal.net> wrote:
> Sorry, I don't understand either of your answers. Adding window.parent
> as a new Watch expression shows all the properties of the window, but
> not any of the global variables. Typing dir(parent) or dir(window) in
> the DOM command line gives "ReferenceError: dir is not defined
> { message="dir is not defined", lineNumber=1, more...}".
>
> In any case, even if these methods worked, they are far too cumbersome
> to be useful. What is needed is for the global variables to appear
> automatically in the Watch window, or at least an object that expands
> to showing the global objects.
>
> Here is a sample HTML page with some global variables gn and gs. Can
> you give me step-by-step directions for viewing their values if I am
> at a Javascript breakpoint in frame L?

If you are on a breakpoint in code in frame L, then the global
variable gn and gs are not visible. They are global in the main page,
they are not global in the code in frame L. To verify this you can
set gn="hello" then in L.html add a script tag that has alert(gn).

I believe frame and iframe are similar:
https://developer.mozilla.org/en/HTML/Element/iframe#Scripting

jjb

Sergio Cinos

unread,
Jan 8, 2011, 1:08:32 PM1/8/11
to fir...@googlegroups.com
gn and gs will be visible if you Watch the variable 'window.parent',
as a global variable IS a property of 'window'. Global variables and
'window' properties are the same thing.

--
S.Cinos
JavaScript Developer at Tuenti.com

2011/1/8 John J Barton <johnj...@johnjbarton.com>:

Woody

unread,
Jan 8, 2011, 2:57:49 PM1/8/11
to Firebug
On Jan 8, 10:08 am, Sergio Cinos <sergio.ci...@gmail.com> wrote:
> gn and gs will be visible if you Watch the variable 'window.parent',
> as a global variable IS a property of 'window'. Global variables and
> 'window' properties are the same thing.

I started my script, and I am at a breakpoint in L (in the onclick
handler). I have the Script tab displayed, and in the Watch/New watch
expression box I typed window.parent. When I expand window.parent by
clicking +, I get a long list of properties, innerHeight,
innerWidth, ..., window. When I expand window, I see my global
variables. The path is ["window.parent"].window.gn. So it appears I
should be entering either window.parent.window (to see all variables),
or window.parent.gn, to see a specific variable.

I did verify that variables that are global to L can be viewed by
entering the variable name into the New watch expression box.

So, I have a feature request. First, Watch should display at the top
of the list, "Global variables". Expanding this would list all the
variables that were global in the current function. Second, if frames
are in use, another item at the top should be "Variables in other
frames". Expanding that would give a list of frames, and expanding
each frame would show its global variables.

But before all this, there is another problem: the Watch window
doesn't display variables consistently. Sometimes it shows the global
variables in window.parent.window, and sometimes not. And sometimes it
shows NO variables at all when stopped at a breakpoint in L.

John J Barton

unread,
Jan 9, 2011, 12:54:53 PM1/9/11
to Firebug


On Jan 8, 11:57 am, Woody <ols6...@sbcglobal.net> wrote:
> On Jan 8, 10:08 am, Sergio Cinos <sergio.ci...@gmail.com> wrote:
>
> > gn and gs will be visible if you Watch the variable 'window.parent',
> > as a global variable IS a property of 'window'. Global variables and
> > 'window' properties are the same thing.
>
> I started my script, and I am at a breakpoint in L (in the onclick
> handler). I have the Script tab displayed, and in the Watch/New watch
> expression box I typed window.parent. When I expand window.parent by
> clicking +, I get a long list of properties, innerHeight,
> innerWidth, ..., window. When I expand window, I see my global
> variables. The path is ["window.parent"].window.gn. So it  appears I
> should be entering either window.parent.window (to see all variables),
> or window.parent.gn, to see a specific variable.
>
> I did verify that variables that are global to L can be viewed by
> entering the variable name into the New watch expression box.
>
> So, I have a feature request. First, Watch should display at the top
> of the list, "Global variables". Expanding this would list all the

The global scope is already shown at the bottom of the Watch panel.

> variables that were global in the current function. Second, if frames
> are in use, another item at the top should be "Variables in other
> frames". Expanding that would give a list of frames, and expanding
> each frame would show its global variables.

The global variables for other frames are already available via
1) window.parent expansion in the Watch panel as above.
2) |window.parent| expression in the Watch panel as above.
2) Command line with cd/dir
3) DOM panel via window.frames

>
> But before all this, there is another problem: the Watch window
> doesn't display variables consistently. Sometimes it shows the global
> variables in window.parent.window, and sometimes not. And sometimes it
> shows NO variables at all when stopped at a breakpoint in L.

I guess you are running Firebug 1.6.0 on Firefox 3.6. Update to 1.6.1
and if you still have a problem report it to our bug tracker.

jjb

Woody

unread,
Jan 9, 2011, 2:23:26 PM1/9/11
to Firebug
I am running v1.6X.1b2, which I understand is the latest available.

> The global scope is already shown at the bottom of the Watch panel.

I am guessing you mean the entry "object window". That does show some
global variables.

>   3) DOM panel via window.frames

Seems to work!

> I guess you are running Firebug 1.6.0 on Firefox 3.6. Update to 1.6.1
> and if you still have a problem report it to our bug tracker.

At the moment, doesn't seem to be reproducible. I am new to JavaScript
and Firebug, so it's hard for me to tell when things aren't working as
they should. Perhaps you can recommend some documentation for how to
use Firebug. What is listed on the web site is interesting, but not
too useful.

Anyway, thanks for your patient help.

John J Barton

unread,
Jan 9, 2011, 11:29:07 PM1/9/11
to Firebug


On Jan 9, 11:23 am, Woody <ols6...@sbcglobal.net> wrote:
> I am running v1.6X.1b2, which I understand is the latest available.
>
> > The global scope is already shown at the bottom of the Watch panel.
>
> I am guessing you mean the entry "object window". That does show some
> global variables.

It should show you all of the properties of the global object for the
window containing the function you called. If you are in a frame, that
will be the global object of the frame, it will not be the global
object of the main window.

>
> >   3) DOM panel via window.frames
>
> Seems to work!
>
> > I guess you are running Firebug 1.6.0 on Firefox 3.6. Update to 1.6.1
> > and if you still have a problem report it to our bug tracker.
>
> At the moment, doesn't seem to be reproducible. I am new to JavaScript
> and Firebug, so it's hard for me to tell when things aren't working as
> they should. Perhaps you can recommend some documentation for how to
> use Firebug. What is listed on the web site is interesting, but not
> too useful.

This is what we have:
http://getfirebug.com/wiki/index.php/FAQ

jjb
Reply all
Reply to author
Forward
0 new messages