How can I execute DOM-reliant javascript in deno_core?
I just want to execute some javascript in the background of my rust app, but I need a virtual dom to use some modules. I'm brand new to deno/rust, so apologies if I'm missing something obvious. But I don't understand if what I'm trying to do is even possible lol.
I'm trying to get linkedom to work with deno_core, but I get the error
when I run the JsRuntime eventloop that imports linkedom.
This is my javascript file, following the example from https://docs.deno.com/runtime/manual/advanced/jsx_dom/linkedom/
this is my rust function to execute the js file
8 Replies
I'm sorry, but I wasn't able to find the answer to your question in the official Deno documentation. However, based on the error message you've provided and the code snippet, it seems like the issue is related to the
window
object not being defined in the Deno environment you are running.
Deno does not provide a window
object by default as it is not a browser environment. The window
object is specific to browser environments, and Deno is a runtime for executing JavaScript outside of the browser, similar to how Node.js operates.
The linkedom
library you are trying to use is designed to work with a DOM environment, and it seems like it's expecting a window
object to be present, which is not the case in Deno's default runtime.
Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of the advice given. You may need to look for a library or a way to create a virtual DOM environment within Deno that can provide a window
object or find an alternative approach that does not rely on window
being defined.
For executing DOM-reliant JavaScript in Deno, you might need to use a library that can simulate the browser environment, such as jsdom
or another virtual DOM implementation that is compatible with Deno. However, integrating such a library with deno_core
and Rust might require additional setup and compatibility checks.
Remember to check if there's a Deno-compatible version of linkedom
or any other virtual DOM library you wish to use, and ensure that it can work without relying on browser-specific objects like window
.What's the error you're getting? You'll probably need the web extension at least
If it’s unclear I’m trying to use the deno_core crate in a rust desktop application, not a browser or web app.
Yes I figured
So youll need to set up window yourself in the global scope, the runtime doesn't do that for you
You can find an example on the deno GitHub, in runtime/js
Thanks!
Lemme know if you have more questions
where can I read more about how to use the deno_web extension? I updated my code to use a MainWorker like the runtime/js example did. So I've least progressed to another error,
LocalStorage is not supported in this context
. But again I'm not really sure what I'm doing or why I'm doing it with these snippets, I'm not seeing a guide but maybe I'm not looking hard enough