Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webui_exit does not work when using a link to navigate a page #228

Closed
ttytm opened this issue Sep 24, 2023 · 9 comments
Closed

webui_exit does not work when using a link to navigate a page #228

ttytm opened this issue Sep 24, 2023 · 9 comments

Comments

@ttytm
Copy link
Member

ttytm commented Sep 24, 2023

webui_exit won't work after changing a page through a link, e.g. in the serve a folder example. The window will stay open.
It works when programatically changing the page via the backend.

@fibodevy
Copy link
Contributor

Thats because webui.js is not loaded there. When changing the page the websocket connection drops, on the new page if there is no <script src="/webui.js"> then it wont reconnect. WebUI cant control the browser and cannot close it, at this point webui_wait() returns and browser window remains open.

@ttytm
Copy link
Member Author

ttytm commented Sep 24, 2023

Tho with the second.html in the mentioned example, webui.js is included on the page.

https://github.com/webui-dev/webui/blob/main/examples/C/serve_a_folder/second.html

@ttytm
Copy link
Member Author

ttytm commented Sep 24, 2023

One solution would be to state it as a requirement that page navigation inside the webui application requires a programmatic approach from the backend and adjust the example.

@fibodevy
Copy link
Contributor

Right, in simple link exit doesnt work.

I think this has something to do with bindings. Both buttons call webui_show() which I think re-binds to the DOM elements. If direct link is clicked new page is opened directly by the browser and no re-binding by WebUI is done. Events such as clicks are still captured, but #Exit element is not binded.

@fibodevy
Copy link
Contributor

fibodevy commented Sep 24, 2023

Found the problem. Bindings are ok, that would be weird coz they are in webui.js..

The problem is that the window cant be closed by script if that script didnt open that window. Security measures. And in this case the script (webui.js) didnt open the window, you did by clicking the link.

m35SevnWWq

Its a bug in the example, not WebUI.

One solution would be to state it as a requirement that page navigation inside the webui application requires a programmatic approach from the backend and adjust the example.

Agree. I always had in mind WebUI is a solution that "loads the page once", and all things must be done dynamically.

@ttytm
Copy link
Member Author

ttytm commented Sep 24, 2023

Found the problem. Bindings are ok, that would be weird coz they are in webui.js..

The problem is that the window cant be closed by script if that script didnt open that window. Security measures. And in this case the script (webui.js) didnt open the window, you did by clicking the link.

m35SevnWWq

Good find!

WebUI cant control the browser and cannot close it, at this point webui_wait() returns and browser window remains open.

Hmm, thinking about it, maybe it's possible to control it. WebUI already provides an api to get the process ids, so ending the process on webui_exit should theoretically be possible.

@hassandraga
Copy link
Member

Thank you for the report. Fixing this issue led to the creation of a new API.

Now, when using all-events webui_bind(MyWindow, "", events) WebUI then will block all href requests, then the user will receive the event and decide to call webui_navigate() or not.

If no all-events is used, then everything will work as normal.

@fibodevy
Copy link
Contributor

@hassandraga can you check if this new feature, catching all hrefs, works on Firefox? In my case it doesnt, on Chrome & Edge it works.

@hassandraga
Copy link
Member

I did not test it in Firefox. I will double-check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants