1

I'm trying to implement an application to interact with a website(similar to selenium) using the v8 engine. If I load a string that represents the HTML into the v8 javascript, what's the best way to interact with it. From what I've looked at, there seem to be two possible solutions: (1) Implement the DOM manually using C++ and bind it to v8 or (2) Find an existing DOM model and use that.

Which one of these solutions would be easier, or is there another better solution?

1 Answers1

0

Using an existing implementation is a lot easier than writing your own. The DOM is huge.

In fact, I'd go as far as saying: to interact with a website, you don't want just a JavaScript engine (like V8) with a few additions. You most probably want a full web renderer. I don't have any specific suggestions (1) because I don't know that space very well and (2) because you haven't described what exactly you want to do. It could be that Selenium or Puppeteer are your best options; or maybe the Chromium Embedded Framework; or maybe the Qt WebEngine; etc.

V8 is just a JavaScript engine [1]. It doesn't know anything about HTML, or the DOM, or CSS, etc. var html = "<button onclick=...>click me</button>"; is just a meaningless string to V8. It doesn't know what a button is, or an onclick handler. You can't use it to draw a button onto the screen. If you tried e.g. eval(html), you'd get a SyntaxError, because that string isn't valid JavaScript, and V8 only deals with JavaScript.

[1] or more accurately: an ECMAScript engine. Defining colloquial terms is a bit tricky; some people say that "JavaScript" and "ECMAScript" are synonyms, others say that "JavaScript" == "ECMAScript language core + DOM bindings and other common browser stuff".

jmrk
  • 34,271
  • 7
  • 59
  • 74