Integrating a DOM-capable JavaScript engine in C application

I’m working on a C program that needs to handle complex JavaScript and DOM operations. Right now, I’m manually parsing HTML and executing JavaScript, but it’s becoming too complicated to maintain.

I’ve looked into options like SpiderMonkey, but it lacks DOM support. Headless browsers seem promising, yet I’m not sure how to embed them in C.

My requirements:

  • Must operate with MinGW on Windows
  • Should be portable to Raspberry Pi later
  • Needs full DOM implementation
  • Preferably a pure C solution or one that’s easily compilable

Has anyone successfully integrated a JavaScript engine with DOM capabilities into a C application? I’m open to suggestions on libraries or methods that could work for this situation. Thanks for any advice!

have u considered using WebKit? it offers full dom support and can be embedded in c apps. i used it in projects on windows and pi. there’s a learning curve, but it can be worth it. just check your resources, esp. for the pi.

Have you considered using CEF (Chromium Embedded Framework)? It’s a robust solution that meets your requirements. CEF provides a full-featured browser engine, including DOM support, and can be integrated into C applications. It works on Windows with MinGW and can be ported to Raspberry Pi.

While CEF isn’t a pure C solution, it offers C API bindings. The setup process can be complex, but it’s well-documented. One advantage is that it uses the same rendering engine as Chrome, ensuring compatibility with modern web standards.

Keep in mind that CEF has a larger footprint than some alternatives, which might impact performance on resource-constrained devices like the Raspberry Pi. However, for complex JavaScript and DOM operations, it’s often worth the trade-off.

I’ve actually tackled a similar challenge in one of my projects. Have you looked into libxml2 combined with Duktape? Libxml2 gives you robust HTML parsing and DOM manipulation, while Duktape is a lightweight JavaScript engine that’s easy to embed. They work well together and meet your portability requirements.

For DOM operations, you’d use libxml2’s functions to create and modify the document structure. Then, you can expose these operations to Duktape, allowing your JavaScript code to interact with the DOM.

It took some time to set up, but once it was working, it was quite powerful. The combo is less resource-intensive than full browsers, which is great for Raspberry Pi. Just be prepared for some initial complexity in bridging the two libraries.