14

Is there an implementation or emulation of the DOM which is purely javascript?

  • There is env.js, but that requires Rhino.
  • There's jsdom, but that requires Node.

Is there a solution that works in most any javascript interpreter, such as v8, without being tied to any particular interpreter or engine? That is, is there any DOM implementation in JS that without any set up or shims can be dropped into a javascript interpreter and just run?

4
  • Could you explain why you need this? Commented Mar 15, 2012 at 18:38
  • It's to test javascript code. Commented Mar 17, 2012 at 2:30
  • 1
    I am looking for something similar, here is the reason for me: I want to run it in v8 js engine (controlled by golang bindings to v8), but not necessarily in node. Commented Jun 2, 2015 at 21:54
  • @JPuge Questions like this always turn out to be retarded as the time goes on. The reasons may include: Using DOM in web workers, using DOM in custom native application that runs HTML and Javascript, using javascript to validate some HTML files... Commented Nov 11, 2015 at 13:07

2 Answers 2

5

In addition to the ones you have listed, I have heard good things about dom.js. It requires limited ES6 features such as const, WeakMap, and Proxy, so it will work in V8 and SpiderMonkey (Rhino) but not JavaScriptCore, Chakra, or others.

Sign up to request clarification or add additional context in comments.

Comments

1

It's hard to guess at exactly what you're trying to do, here, but I'll take a stab at it, just to keep the conversation going:

  • If you're trying to manipulate a DOM from within a browser, can't you just use Jquery?
  • If you're trying to get a "headless browser", I'd check out PhantomJS.

I guess it's hard to imagine how you'd even run Javascript code without a browser, or Rhino, or Node, or PhantomJS, or some other JS interpreter environment...

3 Comments

If you're trying to manipulate a DOM from within a browser, can't you just use the DOM API?
I realize this is not the same... however for what he's asking for teaching people how to use the DOM api and not abstracting a layer on top of it would be best.
Actually, it's to abstract out the DOM away from browsers and their trappings to test code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.