如何将 DOM API 合并或实现到 v8?
我正在编写一个服务器应用程序,它能够在将 DOM 提供给客户端之前对其进行操作。
我使用 C++ 和 Google 的 v8 作为 javascript 引擎,但我在 v8 中没有看到任何 DOM API。
是否有一个开源实现可以在 HTML 上进行 DOM 操作?
如果不是,您将如何实施?
I am writing a server application that is able to manipulate the DOM before it is served to the client.
I am using C++ and Google's v8 as a javascript engine but I don't see any DOM API in v8.
Is there an open source implementation for doing DOM manipulation on HTML?
If not how would you implement one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
DOM 在 Chrome 中创建并链接到 V8 引擎。 V8 源代码对浏览器 DOM 一无所知。 让这个为你工作的最快方法是尝试提取 Chrome(实际上是 Chromium)将 HTML 加载到结构中的部分,以及将 DOM 和 DOM 方法链接到 V8 的部分。 情况可能没有你想象的那么糟糕。 如果说有什么不同的话,那就是 Google 生成了相当干净的 C++,据我通过查看 V8 源代码得知。 情况可能没有你想象的那么糟糕。
The DOM is created and linked to the V8 engine in Chrome. The V8 sources know nothing about the browser DOM. The quickest way to get this working for you would be to try to extract the parts of Chrome (Chromium, really) that load HTML into a structure, and the parts that link the DOM and DOM methods into V8. It's probably not as bad as you think. If anything, Google produces pretty clean C++, as far as I can tell from looking at the V8 source code. It's probably not as bad as you think.
您查看过 CplusplusDOM 吗? (它是在您提出问题后创建的)
Have you checked out CplusplusDOM? (which has been created after your question was asked)
由于您已经(据我所知)用 C++ 实现了自己的 dom 实现,并且只需要 JS dom 绑定,我相信在 JS 映射低级 JS 函数到您已有的接口中实现大部分内容会更容易
As you already have (as I understood) your own dom implementation in C++ and only need JS dom binding, I believe it would be easier to implement most part of it in JS mapping low-level JS functions to interface you already have
Safari/Chrome 使用 Webkit 渲染引擎,它结合了 CSS 渲染和 DOM,我想说它是除了 Opera 之外最好的渲染引擎之一 - 我认为它可能有用:
http://webkit.org/
Safari/Chrome use the Webkit rendering engine, which incorporates CSS rendering and the DOM, I would say it's one of the best rendering engines in addition to Opera's - I think it could be of use:
http://webkit.org/
截至 2018 年,Cloudflare Workers 在 V8 引擎上运行,一些开发人员一直在调查如何访问 DOM 解析和操作。 他们发现了 dom-parser 和 cheerio,因此这些可能可以满足您的需求。 Cheerio 提供了有用的类似 jQuery 的语法。 它们是 NodeJS 模块,但看起来它们可能能够在 V8 中运行。
请参阅:https://simon-thompson.me /simple-dom-manipulation-via-jquery-in-cloudflare-workers/
As of 2018, Cloudflare Workers run on the V8 engine and some devs have been investigating how to access DOM parsing and manipulation. They discovered dom-parser and cheerio, so it's possible these might provide what you need. Cheerio provides a helpful jQuery-like syntax. They are NodeJS modules, but it appears that they might be able to run within V8.
See: https://simon-thompson.me/simple-dom-manipulation-via-jquery-in-cloudflare-workers/