Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

access event object in Extension Developer's JS shell?

25 views
Skip to first unread message

Li Hong

unread,
Dec 25, 2009, 8:44:55 PM12/25/09
to dev-ext...@lists.mozilla.org
How to use the Javascript shell of Extention Developer extension, how I
access an event?

For example,
function exampleforload(event)
{
...
var newTabBrowser = gBrowser.getBrowserForTab(event.target);
...
}

What shall I put in the JS shell? gBrowser.getBrowserForTab("load".target)
brings "aTab is undefined" error msg.

Eric Jung

unread,
Dec 26, 2009, 6:37:08 AM12/26/09
to dev-ext...@lists.mozilla.org

First, make sure you set the context to browser.xul by clicking the
enumerateWindows() link (or typing it), then clicking the
chrome://browser/content/browser.xul<javascript:go('scope(Shell.enumWins[2])')>link.

Then, enter your code. If you enter precisely:
gBrowser.getBrowserForTab("load".target)

and get this error:
TypeError on line 1899: aTab is undefined

then my guess is there's no tab defined as "load". You can look at the
source for getBrowserForTab() by viewing tabbrowser.xml. For example:
http://mxr.mozilla.org/mozilla1.9.2/source/browser/base/content/tabbrowser.xml#1846(this
may or may not be the version running in your browser since it's
branch 1.9.2).

Eric

Li Hong

unread,
Dec 27, 2009, 1:19:30 AM12/27/09
to dev-ext...@lists.mozilla.org


Thanks Eric.

I did set the context to browser.xul from your previous help.

What I am trying to do with JS shell is to replicate my code which is
gBrowser.getBrowserForTab(event.target) in my JS file. This code is in the
event handerl I've setup for load(). That's why I am typing
gBrowser.getBrowserForTab("load".target) hoping JS shell can figure out
"load" is an event.

Seems it does not.

Is it possible to use JS shell for event related debugging like what I am
trying to do above?


Li Hong

Eric Jung

unread,
Dec 27, 2009, 5:04:27 PM12/27/09
to Li Hong, dev-ext...@lists.mozilla.org
On Sun, Dec 27, 2009 at 1:19 AM, Li Hong <cef...@gmail.com> wrote:

> >
> > On Fri, Dec 25, 2009 at 8:44 PM, Li Hong <cef...@gmail.com> wrote:
> >
> > > How to use the Javascript shell of Extention Developer extension, how I
> > > access an event?
> > >
> > > For example,
> > > function exampleforload(event)
> > > {
> > > ...
> > > var newTabBrowser = gBrowser.getBrowserForTab(event.target);
> > > ...
> > > }
> > >
> > > What shall I put in the JS shell?
> > gBrowser.getBrowserForTab("load".target)
> > > brings "aTab is undefined" error msg.
> > >
> > >
> > First, make sure you set the context to browser.xul by clicking the
> > enumerateWindows() link (or typing it), then clicking the
> >
> >
> chrome://browser/content/browser.xul<javascript:go('scope(Shell.enumWins[2])')>link.
> >
> > Then, enter your code. If you enter precisely:
> > gBrowser.getBrowserForTab("load".target)
> >
> > and get this error:
> > TypeError on line 1899: aTab is undefined
> >
> > then my guess is there's no tab defined as "load". You can look at the
> > source for getBrowserForTab() by viewing tabbrowser.xml. For example:
> >
> >

> http://mxr.mozilla.org/mozilla1.9.2/source/browser/base/content/tabbrowser.xml#1846(this<http://mxr.mozilla.org/mozilla1.9.2/source/browser/base/content/tabbrowser.xml#1846%28this>


> > may or may not be the version running in your browser since it's
> > branch 1.9.2).
> >
> > Eric
>
>
> Thanks Eric.
>
> I did set the context to browser.xul from your previous help.
>
> What I am trying to do with JS shell is to replicate my code which is
> gBrowser.getBrowserForTab(event.target) in my JS file. This code is in the
> event handerl I've setup for load(). That's why I am typing
> gBrowser.getBrowserForTab("load".target) hoping JS shell can figure out
> "load" is an event.
>
> Seems it does not.
>
> Is it possible to use JS shell for event related debugging like what I am
> trying to do above?
>
>

I don't really know what you're trying to do above. But there is an Event
object you can create:
https://developer.mozilla.org/en/DOM/document.createEvent
However, you might find it easier to use dump() statements in your code for
some debugging tasks instead of JSShell. dump("some string" + variableName +
"\n") outputs to stdout. On some operating systems, you have to start
firefox with the -console command-line argument in order to see stdout.

Eric

Li Hong

unread,
Dec 27, 2009, 6:52:35 PM12/27/09
to eric...@yahoo.com, dev-ext...@lists.mozilla.org
I will try the dump() way.

Basically I am trying to access an event object via JS shell to see for
example if event.target is the one I am expecting.


--
Li Hong

0 new messages