Bun/Deno crash: `webui_show` and `webui_is_shown` not returning correct values
With this Bun wrapper (tested also with Deno) the window crashes after the timeout for not receiving is_shown as true even though the window is displayed correctly after launch.
When debugging I found that in WebUI.show and WebUI.showBrowser the calls to webui_show and webui_show_browser respectively also on isShow the webui_is_shown don't return true correctly when the window is displayed.
Test code:
import { WebUI } from "@webui-dev/bun-webui";
const app = new WebUI();
await app.show("<html><body><h1>Hello World</h1></body></html>");
await WebUI.wait();
I have tried increasing the timeout with WebUI.setTimeout but in any case the app crashes with the following error after roughly 1 minute regardles of a higher timeout.
I believe this is not Bun specific as my tests with Deno came with the same results
While investigating I have commented the checks under show and showBrowser in webui.ts to see if that would allow the app to continue running, but after the ~1min mark it still closes regardless of a highter timeout.
$ ~/dev/webui-test
> bun run index.ts
215 | toCString(content),
216 | );
217 | if (!this.#isFileHandler) {
218 | // Check if window is launched
219 | if (!status) {
220 | throw new WebUIError(`unable to start the browser`);
^
error: unable to start the browser
at new WebUIError (1:23)
at show (/Users/wesleycoder/dev/webui-test/node_modules/@webui-dev/bun-webui/src/webui.ts:220:15)
at show (/Users/wesleycoder/dev/webui-test/node_modules/@webui-dev/bun-webui/src/webui.ts:212:14)
at /Users/wesleycoder/dev/webui-test/index.ts:4:11
Bun v1.2.18 (macOS arm64)
System info:
$ ~/dev/webui-test
> sw_vers
ProductName: macOS
ProductVersion: 26.0
BuildVersion: 25A5306g
$ ~/dev/webui-test
> sysctl -n hw.model
MacBookPro18,3
I think webui will throw new WebUIError() when there is no connection between backend (Bun/Deno) and the frontend (web browser window). You should add webui.js to your HTML code, like this:
await app.show(`<html><body><script src="webui.js"></script><h1>Hello World</h1></body></html>`);
You are using macOS, please keep in mind that webui still have that dock icon issue.
https://github.com/webui-dev/webui/issues/278
Ok, that's good to know, I had removed the script trying to narrow down the issue.
I have added webui.js back to the code, but now I'm back to the window opening and the app freezing completely when using show or showWebView, but the nice thing is that showBrowser with WebUI.Browser.AnyBrowser now opens up correctly which will work for my purposes 🎉
Testing with Deno I seem to be on the same error case as here.
I don't really know if the app freezing on Bun and breaking on Deno are related issues, but they break at the same point (show/showWebView).
I'm available to help in any way you need if you wanna throw any hypothesis for me to test with either deno or bun.
Or if we already got this on track on other issues I'm cool with closing this one too. Either way I'm thankful 😃
Edit: I have tried changing nonblocking to false without any change on the behavior
My understanding its a macos issue for now, those functions need to run on another thread otherwise they will block, on linux that works fine, on mac it will crash, so by making it run on one thread (with nonblocking:false) it doesn't crash but it will block