Need help with firefox extension extending firebug

95 views
Skip to first unread message

Andrew R

unread,
Jan 30, 2009, 1:56:47 AM1/30/09
to Firebug
This is not directly related to firebug, but I think you guys can
help.

In an extension that extends firebug, I am trying to create a
JavaScript object from javascript in the page using the mozilla
sandbox:

var evalInSandbox = function(win, script, vars)
{
win = getUnwrapped(win);
var sandbox = new Components.utils.Sandbox(win);
sandbox.window = win;
sandbox.document = sandbox.window.document;
sandbox.XPathResult = Components.interfaces.nsIDOMXPathResult;
sandbox.__proto__ = win;
if (vars)
{
for (var prop in vars)
{
sandbox[prop] = vars[prop];
}
}
return Components.utils.evalInSandbox(
"(function() { " + script + "\n })();", sandbox);
};


My code that I am trying to run:

evalInSandbox(context.window,
'var comp = AdfPage.PAGE.findComponent("testlink");' +
'var evt = new AdfActionEvent(comp);' +
'evt.queue(true);');

This is an Oracle ADF page where we have AdfActionEvent. This code has
the "evt" as the component (comp == evt). So I tried new
window.AdfActionEvent(comp), but I end up with this error: "Error:
Illegal value = NS_ERROR_ILLEGAL_VALUE
Source file: chrome://oracleadfv/content/common.js
Line: 62"

Do you guys have any idea how I can create a JS object defined in the
page from my extension safely?

Thanks,
Andrew

Andrew R

unread,
Jan 30, 2009, 2:16:15 AM1/30/09
to Firebug
By the way, I am not using Firebug.CommandLine.evaluate* methods, due
to the fact in version 1.3, they fail when I call them from my
extension. It seems like 1.3 needs to run some setup before I am
allowed to call those methods (they are not initialized correctly when
my panel is the current one and I am triggering off of my panel's show
event).

Still I am baffled why the 'new ...' would not return me a new object,
but instead give me the component.

Also note that if I run the code in the firebug console command line,
not from my extension's code, everything works. The problem is that I
am having problems determining how in 1.3 of FB to have my extension
act like a user running code in your command line.

Antonin Hildebrand

unread,
Jan 30, 2009, 7:15:02 AM1/30/09
to Firebug
Hi Andrew,

I'm not firefox expert and I know almost nothing about eval-ing
javascripts in sandboxes but I was in the same need of executing
arbitrary javascript in the context of running page and possibly
getting results back to my firebug extension.

I've ripped part of new firebug's commandline functionality and monkey-
patch some other bits:
http://github.com/darwin/firequery/blob/2fcd979cd28d5afda00bcdcf57e721c8323e015c/firefox/chrome/content/firequery.js#L110

regards,
Antonin

Andrew R

unread,
Jan 30, 2009, 11:11:38 AM1/30/09
to Firebug
Thanks, that helped, although I had to tweak the code to get it to
work in Firebug 1.3.0 (Firebug.CommandLine.isReadyElsePreparing no
longer exists).

Hopefully the firebug API settles down a bit and things get easier for
extenders. I'd still really love to know why the code doesn't work in
the FF sandbox though. Everything seems to work, except the "new
SomeObject".

John J Barton

unread,
Jan 30, 2009, 11:31:41 AM1/30/09
to Firebug
Antonin's code probably targets 1.4.

I spent a lot of time with the FF sandbox thing. I eventually gave up
and created the monster we have now for command line evaluation. The
sandbox thing was more a "quicksand box". Every time you tweak it or
try another case it breaks in some way.

If your goal is to create an object in the page the easy way is to
inject a script tag in the page. This is safe for users of your
extension and you know exactly how it works.

jjb

Andrew Robinson

unread,
Jan 30, 2009, 11:40:09 AM1/30/09
to fir...@googlegroups.com
Good point, hopefully FF will make their sandbox more developer
friendly in upcoming releases.

The injecting a script tag into the page: how do you then time code in
your extension so that it runs after the code has been injected? Do
you use firefox events to notify the extension?

-Andrew

John J Barton

unread,
Jan 30, 2009, 11:50:30 AM1/30/09
to Firebug


On Jan 30, 8:40 am, Andrew Robinson <andrew.rw.robin...@gmail.com>
wrote:
...
> The injecting a script tag into the page: how do you then time code in
> your extension so that it runs after the code has been injected? Do
> you use firefox events to notify the extension?

? I'm missing something. In the extension you have:
injectSomeCode();
doSomethingOnInjectedObjects();

jjb

Andrew Robinson

unread,
Jan 30, 2009, 12:04:01 PM1/30/09
to fir...@googlegroups.com
But if injectSomeCode() adds a script element to the page, and you add
it during the DOM ready event, the script source is not necessarily
downloaded and parsed until the page load, so:

injectSomeCode();
doSomethingOnInjectedObjects(); // will throw object not defined errors

right?

-Andrew

sdgsfdg dhsh

unread,
Jan 30, 2009, 12:13:17 PM1/30/09
to fir...@googlegroups.com
Hi,can you help me work out how to get a moving back ground on my you tube channel using firebug please,i have only just downloaded the firebug add on so am not great on it,but i know for sure you can get a moving back ground on you tube using it even though their background upload limit is 256k,i seen lots of channels who have done it recently using firebug but they wont share it with anyone,so please could you help me,thanks.

John J Barton

unread,
Jan 30, 2009, 12:15:37 PM1/30/09
to Firebug
That has not been my experience. Adding script tags is synchronous up
to Firefox 3.1. They are planning to change this 'sometime'.
jjb

On Jan 30, 9:04 am, Andrew Robinson <andrew.rw.robin...@gmail.com>
wrote:
> But if injectSomeCode() adds a script element to the page, and you add
> it during the DOM ready event, the script source is not necessarily
> downloaded and parsed until the page load, so:
>
> injectSomeCode();
> doSomethingOnInjectedObjects(); // will throw object not defined errors
>
> right?
>
> -Andrew
>
> On Fri, Jan 30, 2009 at 9:50 AM, John J Barton
>

Andrew Robinson

unread,
Feb 1, 2009, 9:24:43 PM2/1/09
to fir...@googlegroups.com
BTW, thanks, this is working. I think my problem was creating a SCRIPT
element with a SRC attribute instead of putting the script into the
body of the tag. I guess if 3.1 changes things a whole other approach
will be needed. Perhaps Mozilla will fix some of the sandbox bugs.

-Andrew
Reply all
Reply to author
Forward
0 new messages