Replies: 10 comments 13 replies
-
TauriMight also be worth looking at https://github.com/tauri-apps/tauri. Electron is tightly integrated with Node.js and Chromium. Tauri is not. If you wanted to use Node.js in Tauri, you would run a sidecar process. The comms are done via stdin/stdout though which isn't very efficient. Bun could be used here instead of Node.js. The Tauri plan is also to make it backend-language agnostic:
So Zig could be ultimately used here and Bun too. I would prefer to write a backend in TypeScript running in Bun, and then use Zig FFI. "Web view"FYI. This
Each programming language (e.g. There are three platforms supported:
For Linux, it uses https://github.com/webview/webview/blob/fe765aa38d3425a55b27b1ee4df34d6a53a124d6/webview.h#L455
For macOS, it uses https://developer.apple.com/documentation/webkit/wkwebview
https://github.com/webview/webview/blob/fe765aa38d3425a55b27b1ee4df34d6a53a124d6/webview.h#L640
For Windows, it uses https://github.com/webview/webview/blob/fe765aa38d3425a55b27b1ee4df34d6a53a124d6/webview.h#L1080
Bun + webview.hBun just needs to implement this, and then a window management library (like https://github.com/tauri-apps/tao) and you could have a nice lightweight desktop app platform. With desktop apps, download size and memory usage are usually the biggest concerns. Compared to Electron:
|
Beta Was this translation helpful? Give feedback.
-
Updatehttps://twitter.com/jarredsumner/status/1599662060744626176 Related Discussionshttps://discord.com/channels/876711213126520882/903845031230713857/1048892113586225182 |
Beta Was this translation helpful? Give feedback.
-
Related: Gluon is working on experimental Bun support. Gluon is different than other Electron alternatives in that it uses the Chrome/Chromium/Firefox version installed on the system (rather than shipping a duplicate one, like Electron, or using the native Webview (which results in potential bugs in your app due to browser differences). |
Beta Was this translation helpful? Give feedback.
-
Webview integrations for Bun already exist: (I guess it might also be possible to wrap/extract stuff from Playwright to support many more web runtimes.) But, you also need another set of APIs for more app-like feel and OS integrations (menus, app lifecycle, app store etc). It'd be great for |
Beta Was this translation helpful? Give feedback.
-
Recently learned about Socket Supply. |
Beta Was this translation helpful? Give feedback.
-
Webview type stuff is nothing like Electron though. The whole point of Electron is that I know exactly which version of Chromium I'm receiving and therefore no longer need to worry about which technologies are available on the user's computer. |
Beta Was this translation helpful? Give feedback.
-
Just want to add some more notes from my research. The source code for
An example of a fully-fledged browser running WebKit is here: https://browser.kagi.com/. In the WebKit source tree, there are many examples of building browsers with WKWebView:
What this means is that Bun can:
Since Electron 20 they are sanboxing by default. Which means all comms are via IPC. So I'm not sure if there is much benefit to deeply integrating the JS Runtime with the renderer anymore.
WebView2 RuntimeChrome released a forked WebKit version in 2008 with a multiprocess architecture. WebKit2 was announced in 2010 with its own multiprocess architecture (inspired by and improving on Chrome's). Details here: https://trac.webkit.org/wiki/WebKit2 It looks like there are some good foundations there for building a shared runtime like Microsoft is doing with WebView2 Runtime (https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution). The only downside is there is no browser built with WebKit running on Windows so I don't know how viable WebKit is for windows. But I guess people need to be able to test iOS browser apps so Windows needs to be able to run a proper WebKit. Also, https://github.com/ultralight-ux/Ultralight is commercial WebKit-based librart that works cross-platform. So it definitely is doable. JS + WebView2WebView2 is designed to interop with C# and C++. Not JavaScript. So WebView2 still needs its own "Electron"-style project if we want to use JS code for the logic in the "main process". The WebView2 API is here:
Seems like there are two main ones dealing with exposing native objects to the web-side code...
Perhaps Bun Desktop could wrap WebView2 and expose+abstract these APIs in TypeScript from a Bun process. The APIs would be abstracted so they work with WKWebView on macOS. And potentially, things that are not possible in WKWebView like this shared buffer stuff could be patched, and a Bun Desktop Runtime could be shipped with the patched WKWebView. When WebView2 releases for macOS, then this patch can be deprecated. Or perhaps there are cool macOS/Linux specific features that could be kept. Electron's history with Chromiumhttps://www.electronjs.org/blog/electron-internals-building-chromium-as-a-library:
Incredible to see the hoops they jump through to use Chromium as a library...whereas WebKit has always been designed to be an embeddable control. The WebView control code was first added 2001/12/07, 4 months after the WebKit project was kicked off. This made sense for Apple because they built an OS, whereas Google did not. |
Beta Was this translation helpful? Give feedback.
-
I am using zig + webview in my project, the macos part was super-easy (except the SwiftUI compile/linking step, but maybe bun would be fine with objective-c which can be compiled & linked by zig) but the windows part was way trickier because of COM and you still need to distribute WebView2Loader.dll with your project. Here's respective source-code if anyone want to take stab into that But as noted before, webview-based solution is very different from electron. I could afford that but there are many cases where you really need to have control, because different versions behave differently. BTW: even in my case, there's a (JS) bug only happening in macOS Monterey which I couldn't find easily so I left it for later. |
Beta Was this translation helpful? Give feedback.
-
I really wanted this to exist so I've been cranking away at something I'm calling Electrobun over at https://github.com/blackboardsh/electrobun for the last month or so. I plan to spend at least the next two years building this and some related open source things. Aiming for something like a rust-less Tauri (Bun + zig + system webview) with an option to bundle and include a cross-platform webview like CEF, where you as a developer only need to write typescript, with an easy to use typed RPC mechanism between bun and webviews. Some project goals:
Current build sizes:
Current status:It's very early, I'm currently pushing directly to main but will switch to a more stable PR-based flow that's open to code contribution and more thorough documentation once the major churn and initial mechanisms like updating and intel-mac builds are working in a month or two. In the meantime if you want star, follow, join the discord, etc. General architecture is implemented. It gives you a config file to describe typescript entrypoints for bun and each webview and copy other assets into the bundle to be exposed by a views:// scheme to webviews, bundles bun and webview typescript using bun build and constructs a macos bundle. Typescript apis for bun process and webviews. It uses objc statically linked into a zig process. The zig layer will provide cross platform native functionality wrapper for webview, system tray, etc. In dev mode it uses a bun single-file-executable cli both inside the bundle as a launcher and outside the macos bundle as a debug tool to stream logs and provide future advanced debugging abilities. in canary and stable builds of your app it uses a smol zig launcher in the bundle instead. It uses typescript typed RPC to communicate between bun and webviews and bun and zig. I've implemented typed rpc in zig for under-the-hood bun <-> zig rpc with a promise-like behaviour to power exposing things like a Example appCurrently the example in the repo opens two windows.
up next:
|
Beta Was this translation helpful? Give feedback.
-
Prior art: https://neutralino.js.org/ I'm not seeing it mentioned much. I used neutralino and had a good experience. would be nice to have bun cli command that packages up a binary like this. |
Beta Was this translation helpful? Give feedback.
-
Would be nice to have a cleaner, simpler desktop story for JS than Electron. And with easier native bindings.
Probably good to look at WebView2's innovations as it looks like Microsoft's own replacement of Electron...
https://dev.to/noseratio/some-thoughts-on-the-new-microsoft-teams-2-0-architecture-webview2-reactjs-1gf1
Beta Was this translation helpful? Give feedback.
All reactions