Skip to content

Explore adding bindings to the webview library to allow creating web-based frontends #160

@rdw-software

Description

@rdw-software

So this is a weird idea (and probably stupid), but I recently stumbled upon webview while working on some unrelated frontend stuff. Now the big question is, what if we called into that from Lua? (or C, for that matter) It sounds so absurd that it might just work...

Goals:

  • Can create a fully-featured web frontend (including WebGL/WebAudio and CSS-styled UIs) with full control over the backend
  • Can access the builtin libraries from the JavaScript environment (similar to how NodeJS is exposed in Electron)

Roadmap:

  • Implement run_once API to allow integrating webview with libuv's event loop from C
  • Add LuaJIT FFI bindings to access the webview APIs
  • Implement a pull-style API for exchanging messages with the JavaScript context
    • Option 1: SharedArayBuffer (need to check platform support)
    • Option 2: Transferable buffers with window.postMessage (need to check how to get at the buffer from C/Lua)
    • Option 3: Local hosted HTTP server (bad solution, better find a direct way of messaging that works)
    • Option 4: IPC or WebSockets (still too much overhead?)
    • Option 5: Call into C from JS via webview_bind (need to check if it can exchange data)
    • Just use the default JSON RPC (will suck for large messages, so use HTTP/WS for those?)
    • At this point, might as well use WebSockets exclusively and get messages and streaming via TCP for free
  • Tests for typical scenarios, like TCP messaging or file system requests
  • Benchmarks for the various options (if there are several that turn out to work)
  • Investigate native platform capabilities to determine what/if other APIs to add (must exist on all platforms)
  • Add some documentation for the entire thing (API, background info, limitations, design decisions)
  • Upstream as many API changes as possible (if they will take them)
  • Update the build process to statically link webview (and the native SDK dynamically)
  • Update the changelog since this is a "notable change"

What are the drawbacks? Well, there's a few...

  • The library is tiny and it's unclear how well it is maintained... it looks to be actively developed now, but that wasn't always the case
  • The current threading model doesn't makes it easy to control the main loop from outside, though it seems that could be changed
  • The docs are really bad, which doesn't inspire confidence. Then again, the library is a tiny wrapper and proper docs could be added
  • On Windows, the WebView2 runtime cannot currently be linked statically due to Microsoft holding the entry point hostage (proprietary Loader DLL) - this might eventually change since there's a PR that seems to replace it with an open source wrapper
  • Even if you did link it statically, the browser runtime is gigantic (like, 250 MB) so that would be even worse than Electron
  • On the other hand, since it's provided by the operating system and NOT embedded this should generally be pretty lightweight
  • However, it MUST be present on the system. That is not the default for Windows 10, so you need to ship it to end users
  • Not all of the features that the native browser implements are exposed, in fact most aren't - Not sure what exactly is missing
  • You would be running a JavaScript engine (V8) AND a Lua engine (LuaJIT), which is pretty wacky on a conceptual level

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions