document.getElementById() returns null when using mozrepl (but not in firebug)
Asked Answered
P

1

2

I'm trying to use the mozrepl Firefox extension to give me a Javascript REPL from within emacs.

I think I've got it set up correctly. I can interact with the REPL from emacs and can explore the document pretty much as described in the tutorial pages. The problem comes when I try to do something really simple, like get a context to a canvas element:

repl> document.getElementById("mycanvas").getContext("2d")
!!! TypeError: document.getElementById("mycanvas") is null

Details:

  message: document.getElementById("mycanvas") is null
  fileName: chrome://mozrepl/content/repl.js -> file:///C:/Users/teamonkey/AppData/Roaming/Mozilla/Firefox/Profiles/chfdenuz.default/mozrepl.tmp.js
  lineNumber: 1
  stack:
    @chrome://mozrepl/content/repl.js -> file:///C:/Users/teamonkey/AppData/Roaming/Mozilla/Firefox/Profiles/chfdenuz.default/mozrepl.tmp.js:1
  name: TypeError

It's not just that particular instance: any call to getElementById will just return null.

If I start up firebug I can enter the same thing and it will return a valid context, but I'd really like to get the REPL working in emacs. I don't think this is a bug but I've probably not configured mozrepl correctly. Can anyone help?

Mozrepl 1.0, Firefox 3.6

Parkman answered 21/3, 2010 at 3:57 Comment(0)
T
3

When you start, you are in the context of browser window itself, not any particular document. You have access to chrome elements (menus, toolbars, tabs, etc). The document object currently refers to browser window.

To switch context to the document in active tab use:

repl.enter(content)

Now document object is the document loaded in active tab, so you have access to its DOM tree nad can manipulate it.

Tollgate answered 22/3, 2010 at 11:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.