I would like to be able to parse and run Javascript in Godot. I'm no talking about the Javascript bridge for webpages, but a separate Script class that is able to handle Javascript. My purpose for this is that I would like to be able to parse script files at runtime and execute them. I'm trying to create a stripped down web browser and would like it to be able to run Javascript. I can't substitute GDScript because Godot has no way to compile and run GDScript at runtime (the Expression class will only let you evaluate a single expression. GDScript's enforced white space rule also makes it impossible to put several commands on a single like, which makes it a bad choice for web documents).

I was looking into GDNative, but it seems a bit redundant to have a Javascript interpreter written in Javascript. Are there any options for loading, parsing and running Javascript at runtime in Godot?

    kitfox

    Short answer is no.
    Godot does not have a JS interpreter built in.
    Godot is open source, and Chromium's JS interpreter V8 is open source, so it is technically possible.

    Long answer is you shouldn't.
    Afaik you'd have to make a build of v8 and set up a bridge for JS code to be executed by v8.

    The problem is that web pages don't just run JavaScript, they have an entire Document that has hooks for interacting with the JavaScript.

    Making a browser with Godot seems like it would be an extraordinary amount of effort and would introduce innumerable security bugs.

    Is there any reason that opening a webpage in the OS's default browser wouldn't work for you?

    https://docs.godotengine.org/en/4.0/classes/class_os.html#class-os-shell-open

    Edit:
    Hm perhaps I was too hasty. Looks like there's a plugin to do this:
    https://github.com/Geequlim/ECMAScript

    No idea how capable or useful it is though. Good luck!

      I can't substitute GDScript because Godot has no way to compile and run GDScript at runtime

      This is incorrect, see my answer here.

      If you are looking for an embedded programming language, Lua would also be a candidate with Godot Lua API.

      Oops, didn't notice you where working on a web browser, in which case Lua wouldn't make any sense.

      stranger_anger I should have said web browser like system. I want to create a set of XML documents with an HTML-like markup that can be parsed and then displayed in a RichTextLabel. I'd also like the pages to embed bits of script that can be compiled and run at runtime. So this isn't a general purpose web browser, but more of a custom parser for an HMTL 1.1 like language where I have complete control over all the documents.

      I've done something similar before in Java using Java's XML transformation tools, integrated Javascript engine and HTML renderer, but Godot doesn't seem to have any of that.

      I'll check out Geequilim's addon, although from the docs it doesn't look like it has been upgraded to work with Godot 4 yet.

      9 months later