javascriptfirefoxfirefox-addonmozillamozrepl

mozrepl: go to the context of the browser window when entering in a new opened window


My problem is that I can not ascend to the browser window context after creating and entering a new window using mozrepl, how to do it?

ubugnu@spin-foam:~$ telnet localhost 4242 | tee -a .repl_log
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

Welcome to MozRepl.

 - If you get stuck at the "...>" prompt, enter a semicolon (;) at the beginning of the line to force evaluation.
 - If you get errors after every character you type, see http://github.com/bard/mozrepl/wikis/troubleshooting (short version: stop using Microsoft telnet, use netcat or putty instead)

Current working context: chrome://browser/content/browser.xul
Current input mode: syntax

repl> repl.print(document.getElementById('toolbar-menubar'))
[object XULElement]
repl> win = open()
[object Window] - {window: {...}, document: {...}, external: {...}, getInterface: function() {...}, console: {...}, sidebar: {...}, performance: {...}, ...}
repl> repl.enter(win)
[object Window] - {window: {...}, document: {...}, InstallTrigger: {...}, external: {...}, webkitNotifications: {...}, getInterface: function() {...}, console: {...}, ...}
repl> repl.print(document.getElementById('toolbar-menubar'))

repl> repl.print("how to ascend to the browser window context?")
how to ascend to the browser window context?
repl> ?

Solution

  • I'm not familiar with mozrepl at all. But from what I see in your code, perhaps you could try win.opener to access the opener of the current window you're in. Like:

    repl.enter(win.opener);
    

    Alternatively you could try to access the most recent window of type "navigator:browser", if you can access components (Cc,Ci,Cu):

    var window=Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator).getMostRecentWindow("navigator:browser");