RFC: Extension Developer Extension

Talk about add-ons and extension development.
Post Reply
tmp007
Posts: 3
Joined: January 19th, 2005, 4:43 pm

chrome privileges

Post by tmp007 »

hi all I found this nice tool & it looks like the best
resource for extension dev.
my q: I am interested in doing some fairly simple tab
functionality.

(if you know of anyone who is maintaining an
extension in this area & is implementing suggestions, plz
let me know, I havent been able to find ppl implementing
other suggestions, although there are various tab browing exts)

best case scenario: I wish there was some way in firefox
to turn on a flag just to let the javascript have chrome privileges.
then I could hack away with javascript quickly. (no, I dont
want to change the source somewhere & recompile firefox,
even though I have downloaded the source..)

lacking this, I would like to use ext-build-ext
to try out/test some code.

I see on the web site it says the javascript environment
has chrome privileges.

however I cant seem to get any of the chrome.

can someone give an example of a call to

document.getElementById('chrome-thing')

that works in the javascript environment. when I call this fn
in the environment for id's that are in the firefox chrome, it only returns null.
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

the "document" of EDE's JS environment is not browser's/mail's main document. You'll need to use
nsIWindowMediator to get the window you need. The example code was posted many times in this forum, I think you'll be able to find it yourself.
Ted Mielczarek
Posts: 1269
Joined: November 5th, 2002, 7:32 am
Location: PA
Contact:

Post by Ted Mielczarek »

Or you could open the Javascript Shell, click "enumerateWindows()" and click on "chrome://browser/content/browser.xul", which puts you right into the scope of the browser window.

It's in the <a href="http://ted.mielczarek.org/code/mozilla/extensiondev/jsshell.png">screenshot</a>, for heaven's sake!

tmp007 : Your confusion is probably about what "chrome" really means. Documents running with "chrome privileges" have full access to XPCOM, which means they can call all the same functions as the browser code itself. If you want to get access to the elements in the browser user interface, your code needs to be executing in the same context as the browser.xul document, which is usually done using overlays. The Javascript Shell can simulate this process using enumerateWindows() and scope(). I think you'll find it meets your needs.
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

Ted,
1- can we have a drop-down list in Javascript Environment that allows us to choose what window to run the code in?
2- looks like clicking links in JS Shell doesn't work in Thunderbird (guess it's related to the fact that default action for links is to pass them to default browser).
3- Are you aware of the strict JS warnings your code produces?
Ted Mielczarek
Posts: 1269
Joined: November 5th, 2002, 7:32 am
Location: PA
Contact:

Post by Ted Mielczarek »

1. Yes, that'd be cool.
2. Yes, that sucks. Not sure what to do about that.
3. No, I should fix those.
tmp007
Posts: 3
Joined: January 19th, 2005, 4:43 pm

easy troubleshooting of chrome

Post by tmp007 »

ok!! thanks to ted M for info on clicking
on scope(). yes I studied his screenshots but
had no idea that scope() does that from the
mere screenshot (I am not a psychic). I just
got it to work.

but what I really wanna know is, shouldnt
there be an easy way to play with the chrome,
using javascript, without having to go thru
the whole convoluted/complicated process of pkging/adding
extensions. I know its a security hole to have
that enabled by default in the browser, but where
is the option to turn it on for a power user?

Ive been thru several online ext
building tutorials, which imho are really hairy,
given that I just wanna play around with the chrome
a little on my own browser. Ive gone thru XUL
refs and havent found anything yet.

ted M's utility comes the closest
& I think I will be using that (its cool stuff), but I will
probably just write some javascript code
in a file and use a javascript include or something
like that to rerun the same code in the
javascript environment. have to figure that out.

re: nsiwindowmediator, I dont see how to
use that right away but will search on it.
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

tmp007: when Ted implements my #1, you'll be able to run the code from JS Environment. Currently you can write scripts in the XUL editor, they will be given chrome perms.
tmp007
Posts: 3
Joined: January 19th, 2005, 4:43 pm

tricks

Post by tmp007 »

ok I hacked a a little more & came up with
this. step by step to access chrome using
a javascript function.

1. go into javascript shell
2. click enumeratewindows() link
3. click on chrome://browser/content/browser.xul link. now its in that scope
4. make global variable of chrome piece.
eg type var boxEl = document.getElementById('status-bar'); where
status-bar is any chrome ID as eg found by the DOM inspector.
5. now boxEl has an objectXULElement.
6. type load("dir/javascript.js"). this javascript can use the boxEl global variable
just defined.

I tried something else, where I just try to access the chrome with a
getElementById call in the loaded javascript file,
after changing the scope,
but that failed. apparently the scope changes after the load or whatever.

lacking that, it would be cool if ext-build-ext allowed what might
be called "stealth extensions". a list of javascript filenames that
could be added/loaded off its menu, in the scope of the browser chrome.
(oh!! and maybe even hotkeys!!). then we have a new hacked "stealth
extension architecture" in firefox that does not require one to
do extensive extension surgery just to play with the chrome.

whats the point of all this? well its an easy way to write javascript
that can access the chrome without all the tedious rigamarole of
packaging up extensions. see, I know javascript just fine, and dont
want to learn the arcana of extension packaging/development just
to do something simple that accesses the firefox chrome.

I do think there should be a way to do this without loading Ted Ms
ext builder ext (nobody else openly
agrees with me yet on that one), but whatever. "code it or shut up,
or shut up and code it", I know :p

next I will try to get some code in the javascript function that
lists all the tabs, what I wanted to do in the 1st place. hopefully,
no obstacles to that.
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

There's Torisugari's Customizable Toolbar buttons, which while doesn't support loading JS files (last time I checked), allows to execute js with chrome perms on a button click. It's not perfect but quite useful for quick hacks.
prez
Posts: 1
Joined: February 11th, 2005, 9:02 am
Location: Warsaw, Poland

Bugs

Post by prez »

I tried to use EDE under Linux and encountered flollowing problems:
- program failled to find zip utility in default path. I found bug and fixed it (I cut declaration of variable zfile from line 583 and pasted it before conditional instruction, because it wasn't visible in blocks of code that check existence of zip utility e.g. under Linux).
So Ted, could you add that fix to official release?
My working version of extensionbuilder.js is available from http://www.ds2.uw.edu.pl/~pstrzelczak/e ... der-new.js

- buttons "Show extension directory" and "Show extension installed directory" seem not to work at all
I didn't follow the code due to lack of time (and I really don't need this functionality but still I want to report it...).
Salva
Posts: 8
Joined: March 19th, 2004, 1:51 pm

Post by Salva »

Hi, I just installed the extension on Windows XP and, although it certainly looks nice, I have been unable to use it. Whenever I click on "Build Extension", in the Extension Builder window, I get a "No suitable zip program found." error message.
I had Cygwin+zip installed, and I've just installed WinZip too, but I keep getting the error message. Does anybody know what could be causing the problem? :-(

I'm using FireFox 1.0, BTW.
Ted Mielczarek
Posts: 1269
Joined: November 5th, 2002, 7:32 am
Location: PA
Contact:

Post by Ted Mielczarek »

prez: sorry, I'm pretty sure I have that fix in my SVN repository, it just never made a public release.

Salva: that's odd, I'll need to look at the code and get back to you. It looks in the registry, but it has to look at strange keys to try to find zip programs, since most of them do not put an install dir in there.
Salva
Posts: 8
Joined: March 19th, 2004, 1:51 pm

Post by Salva »

Winzip finally worked next day. I did nothing as far as I know, maybe using winzip for a day did something that modified the registry?
Nevertheless, from I what I have seen in extensionbuilder.js, you check for cygwin first, and it's not being detected. Even though the registry key seems correct: "Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/" exists in HKEY_LOCAL_MACHINE and points to the correct path (!).
Maybe it's a problem with Firefox 1.0?

It's a shame that I can't get cygwin/zip to work, as I used iZarc and I had no need for winzip. Anyway, it works. If noone else is having problems with cygwin/zip + Firefox 1.0, don't worry about it. I will be happier if you spend time adding features to the extension instead of finding an obscure bug that might have nothing to do with your code ;).
jedbro
Posts: 1899
Joined: November 10th, 2002, 12:35 pm
Location: Mexico / Boulder Co.
Contact:

Post by jedbro »

Ted.
Sorry if this was mentioned before somewhere on this thread (I might have missed it).
Have you thought about a live REGEXP component to the extension? Alot of extension use regexp for gathering data, etc, and it would be nice to have a live version to test it out. Something along the lines of this:
http://www.cuneytyilmaz.com/prog/jrx/

The code is OS, so you can use it in the extension (and modify it)
ericjung
Posts: 846
Joined: August 4th, 2003, 9:32 am

Post by ericjung »

ted, any chance you can add a preference which allows the user to choose if the javascript: console should be displayed whenever the browser initially loads? this would be extremely helpful as the first thing I usually do when starting the browser is type "javscript:"

p.s. I haven't forgotten about our discussion here, and I've started bundling this as an extension for use in Extension Developer.
Post Reply