Custom functions
Posted October 19th, 2007 by bard
MozRepl documentation has moved. Go to the new home »
New commands can be added to the REPL through an initialization file. Go to the about:config URL, find extensions.mozlab.mozrepl.initUrl, and set this value to a local URL (chrome:// or file://). The URL contents will be loaded in the REPL. Example:
- Set extensions.mozlab.mozrepl.initUrl to file://localhost/tmp/custom.js
- Create a /tmp/custom.js with the following content:
var startedAt = new Date();
function report() {
this.print('I was started at ' + startedAt);
}
- Each time you start a REPL, it will now have a startedAt member and a report() method.
I have two files containing a lot of JS code (functions) in them and I'm trying to load them into mozrepl.
I was unable to do this by using the sample above (I'm on windows machine, made sure the right permissions are set.). It's unclear if '/tmp' directory should be located in the root directory of my hard drive or the document root directory of the web server.
Basically, I've written a little PHP server that opens a socket to mozrepl. Once the socket is open, I'm sending through it the content of the two files. In return, I get one of two behavior:
1. Content is sent to mozrepl, but for some reason, the functions that were in that content are still not defined... (opening a raw telnet connection to mozrepl and copying and pasting the same content does solve the problem, but why doesn't it work when I simply write it into the socket??)
2. Something goes wrong while writing the content into the socket and from this moment - the socket is no longer responsive.
Most likely - mozrepl closed it's side of the socket without informing me about it; Same thing happens (sometimes) when I copy&paste large amount of content into a raw telnet connection to mozrepl...
Any help would be greatly appreciated :)
It's unclear if '/tmp' directory should be located in the root directory of my hard drive or the document root directory of the web server.
It should be on the same machine Firefox runs on, since that is where the "load" command is executed.
1. Content is sent to mozrepl, but for some reason, the functions that were in that content are still not defined... (opening a raw telnet connection to mozrepl and copying and pasting the same content does solve the problem, but why doesn't it work when I simply write it into the socket??)
I'm afraid I can't help much with this, it's not exactly among my use cases. :-( However, you might try going the other way around and have MozRepl pull the file via XMLHttpRequest instead of pushing the file to it, then execute from the local hard drive with repl.load().
Post new comment