Tutorial
After connection you'll be in the context of the browser window, i.e. all the code you'll type will be evaluated there:
repl> repl.whereAmI() [object ChromeWindow] - Document title: "Firefox" repl> repl.look() this.repl=[object] this.browserContentListener=[object] this.getInterface=[function] this.XULBrowserWindow=[object] this.tryToClose=[function] this.document=[object] [...]
So typing title will be like typing window.title:
repl> title Firefox
You can modify what you see around, of course. The following changes the window title and hides the toolbar:
repl> title = 'REPL-powered Firefox'
REPL-powered Firefox
repl> document.getElementById('toolbar-menubar').hidden = true
true
You can enter other parts of the interface, have a look, play with things, get online docs for XUL elements (a browser popup appears), then go back:
repl> var c = document.getElementById('urlbar-container')
repl> repl.enter(c)
[object XULElement]
repl> firstChild
[object XULElement]
repl> repl.doc(firstChild)
TYPE: object
NODENAME: textbox
Online help found, displaying...
repl> repl.back()
[object ChromeWindow]
When your curiosity about the browser's insides is satisfied, you might start exploring web pages:
repl> repl.home() [object ChromeWindow] repl> content.location.href = 'http://maps.google.com' http://www.google.com repl> repl.enter(content) // for Firefox 3 you'll need: repl.enter(content.wrappedJSObject) [object Window] repl> repl.whereAmI() [object Window] - Document title: "Google Maps" repl> repl.look() this.G_HYBRID_TYPE=[object] this.G_HYBRID_MAP=[object] this.G_SATELLITE_TYPE=[object] this.G_SATELLITE_MAP=[object] this.G_MAP_TYPE=[object] this.G_NORMAL_MAP=[object] this.G_DEFAULT_MAP_TYPES=[probably array, length 3] this.GAddCopyright=[function] this.GSmartPaste=[function] this.GSendToPhone=[function] [...] repl> repl.search(/app/i) GMapsApplication loadApplication gApplication _mMapPrintUrl XPCNativeWrapper repl> repl.doc(gApplication) TYPE: object repl> repl.enter(gApplication) [object Object] repl> repl.look() this.ra=[object] this.We=[object] this.a=[object] this.Xf=[object] this.Ma=[object] [...] repl> repl.search(/get/) getMap getOverviewMapControl getPageUrl getTabUrl getMarker getPolyline getVPageUrlParams repl> repl.doc(getPageUrl) TYPE: function ARGS: [none declared] repl> getPageUrl() http://maps.google.com/?ll=37.020098,-49.042969&spn=61.328812,93.164062&om=1 repl>
To go back to the context where the REPL was started:
repl> repl.home(); [object ChromeWindow] repl>
Creating a new context and working inside it, e.g. for testing new stuff, is easy, and what you define there, stays there:
repl> var scratch = {}
repl> repl.enter(scratch)
[object Object]
repl> repl.look()
this is empty
repl> var x = 2
repl> var y = 'hello'
repl> x
2
repl> y
hello
repl> repl.look()
this.x=2
this.y=hello
repl> repl.back()
[object ChromeWindow]
repl> x
@data:application/x-javascript,x:1
!!! ReferenceError: x is not defined
repl> y
@data:application/x-javascript,y:1
!!! ReferenceError: y is not defined
repl> scratch.x
2
repl> scratch.y
hello
repl>
Of course, you can also mess with the REPL itself:
repl> repl.enter(repl)
[object Object]
repl> function sayHello() { this.print('hello from repl!') }
repl> sayHello.doc = 'just say hello'
just say hello
repl> repl.back()
[object ChromeWindow]
repl> repl.doc(repl.sayHello)
TYPE: function
NAME: sayHello
ARGS: [none declared]
just say hello
repl> repl.sayHello()
hello from repl!
To find out more about REPL commands, inspect() it, and then use doc() for more specific information.
repl> repl.inspect(repl)
[...]
<object>.back=[function]
<object>.sayHello=[function]
just say hello
<object>.module=[object]
<object>.util=[object]
<object>.setenv=[function]
Takes a name and a value and stores them so that they can be later ...
<object>.getenv=[function]
Given a name, returns a value previously stored via setenv().
<object>.pushenv=[function]
Takes one or more names of values previously stored via setenv(), a...
<object>.popenv=[function]
Takes one or more names of values previously pushed via popenv() an...
<object>.print=[function]
Converts an object to a string and prints the string. Appends a new...
[...]
repl> repl.doc(repl.print)
TYPE: function
NAME: print
ARGS: data, appendNewline
Converts an object to a string and prints the string. Appends a
newline unless false is given as second parameter.
repl>
When you're done:
repl> repl.quit()
Something's missing from this tutorial or the docs - when I type anything, such as the tut's first line, "repl.whereAmI()", I get the following message at every keystroke-
!!! RefernceError: r is not defined
!!! RefernceError: e is not defined
!!! RefernceError: p is not defined
...
Is there some implied mode MozRepl wakes up in, or another mode one need enter in order to enter expressions for evaluation?
Oh, and when I start a new telnet session, first thing it sez is, "Current input mode is: syntax." Also, I did try "set mode console" but no difference. (I'm using cygwin, but telnet's provided by windoze.)
Is there perhaps a list of special keys for switching modes, for typing things other than expressions?? Also, it looks like newlines are getting sent but not carriage returns. That really messes up cygwin/telnet on win.
Thanks - it's an awesome project, and I look forward to learning how to make it work.
Telnetted raw with Putty, and now it accepts a line of characters, but nothing evaluates.
Hi Kevin,
to the best of my knowledge putty works (or so it has been reported). Under cygwin I have used netcat (nc). rlwrap (if you manage to find it) + netcat is probably the optimal solution as it also gives you command history.
Post new comment