webui-dev / webui

Use any web browser or WebView as GUI, with your preferred language in the backend and modern web technologies in the frontend, all in a lightweight portable library.
https://webui.me
MIT License
2.63k stars 157 forks source link

Firefox profiles #224

Closed fibodevy closed 9 months ago

fibodevy commented 10 months ago

If I delete default .WebUI folder from home folder:

   0s app started
   0s window = 1
  10s fail

webui_show_browser fails after 10s. Profile still exists, just files are missing.

Thats why WebUI didnt work with Firefox on my PC for some time 😆 I removed the folder just to cleanup my PC, wasnt aware profile still existed in Profile Manager.

There is at line 2725

sprintf(buf, "%s -CreateProfile \"WebUI %s\"", win->browser_path, firefox_profile_path);
_webui_cmd_sync(win, buf, false);

Its skipped if custom profile is set. I cant find another "CreateProfile" string in file, so looks like custom profile for Firefox isnt created.

Bug

If you set custom profile with webui_set_profile then Firefox will open Profile Manager.

New function

When I asked for webui_set_profile I was thinking to create a temporary profile for the browser and remove it after app exit, or on app uninstallation. But in firefox if you delete the folder, the profile still exists in Profile Manager blocking you from creating a new profile with the same name, and blocking you the use of profile whose files were deleted.

The solution is to create another function webui_delete_profile with 2 variants

  1. delete profile by passing window, it knows the profile name and path
  2. delete any profile by passing: browser type, profile name and profile path

How to delete a Firefox profile? Cant do it from command line AFAIK, so

  1. Delete the profile folder
  2. Delete the profile from INI file %APPDATA%\Mozilla\Firefox\profiles.ini - at least on Windows
hassandraga commented 10 months ago

Actually, webui_set_profile() will create the profile if it does not exist when using a Chromium-based browser, while in Firefox the profile should already exist. To solve this issue we need to find the proper cross-platform way to create and delete Firefox profiles using CLI.

Unfornantly, All those issues exist only in Firefox because the Mozilla profiles manager could be more efficient like the Chromium-based one.

hassandraga commented 10 months ago

By default, we keep the profile folder because this makes the app run faster. But, we can probably create a new API webui_clean():

webui_wait();
webui_clean(); // Delete all local profiles folder
fibodevy commented 10 months ago

But how webui_clean() will know what profiles to delete on application uninstall? Deleting the profile folder on every app exit is not necessary.

Editing INI files is not big deal.

[Profile3]
Name=test
IsRelative=0
Path=C:\temp\_ffprofiletest1

Just match with Name and delete whole [Profile3] block, on other OSes its probably that simple too. Unfortunately CLI for Firefox cant do this.

For Chrome just delete folder and thats it.

bool webui_delete_profile(size_t browser, char* name, char* path);

That thing with not creating a custom profile for Firefox I still consider a bug, especially that webui_show()/webui_show_browser() returns TRUE and some profile manager shows up.

hassandraga commented 10 months ago

returns TRUE and some profile manager shows up

I didn't know that. Thanks for the report. I will try to fix it.

hassandraga commented 10 months ago

how webui_clean() will know what profiles to delete on application uninstall?

I'm not talking about the uninstall process, but simply after webui_wait() returns, the user can optionally call webui_clean() to delete the local profiles folder. This will include deleting the Firefox profile from the INI file as well.

hassandraga commented 10 months ago

If you are using an installer creator, probably you can use webui_set_profile("", "") to completely avoid using new profiles. Another option is using the temp folder, for example webui_set_profile("MyApp", "/tmp/MyAppProfile").

hassandraga commented 10 months ago

If your installer creator can be configured to delete a specific folder when uninstalled, then simply use it to delete /home/user/MyAppProfile.

fibodevy commented 10 months ago

Another option is using the temp folder, for example webui_set_profile("MyApp", "/tmp/MyAppProfile")

Yes, but assuming the profile will be created, if I delete just the folder then the profile in the INI file will remain.

Why doesnt WebUI create custom profiles for Firefox? It creates a WebUI profile if none is set. It can do it, but it does not. And as I said profile manager opens instead of the browser. It should just create new profile as it does if none is set.

Chromium based + Firefox + Safari are main browsers and all features should work for at least these browsers.

If WebUI provides webui_set_profile() then it should also provide webui_delete_profile(). For Chrome just delete the folder. For Firefox delete fhe folder + modify the profiles.ini file. For safari I dont know.

webui_clean() could be wrapper for webui_delete_profile() which would delete all profiles created during session.

Application using WebUI can do it itself, but webui_show() doesnt return which browser was used. So the application would need to call webui_show_browser() with different browsers until success, then it would know what browser should it clean up.

By the way, another proposal

Until recently, if webui_set_hide() was set to true and the browser was Chrome then the browser didnt open, headless didnt work. That allowed one thing - start the server without the browser.

And since we now have webui_get_url() I propose to add a new function webui_start() that would start the server without opening a browser, so users could open the WebUI URL in a WebView or other embedded HTML5 render in their own app, or just in any browser, why not.

fibodevy commented 10 months ago

returns TRUE and some profile manager shows up

I didn't know that. Thanks for the report. I will try to fix it.

Profile Manager shows up and webui_show() returns true in 2 scenarios

1.

eg if you remove the profile but keep the files

2.

ttytm commented 10 months ago

I'm running into a similar issue starting on a blank ubuntu installation. In my case the ~/.WebUI doesn't exist in the first place.

Creating both directories (/.WebUI/WebUIFirefoxProfile) manually solves it.

hassandraga commented 10 months ago

@ttytm can you please delete the .WebUI folder and manually delete the profile firefox -p. Then run firefox -CreateProfile "WebUI /home/parallels/.WebUI/WebUIFirefoxProfile to see if Firefox can create the .WebUI and WebUIFirefoxProfile folders.

ttytm commented 10 months ago

@ttytm can you please delete the .WebUI folder and manually delete the profile firefox -p. Then run firefox -CreateProfile "WebUI /home/parallels/.WebUI/WebUIFirefoxProfile to see if Firefox can create the .WebUI and WebUIFirefoxProfile folders.

Deleted the folder and the profile. There was no WebUI profile so there was only the default profile to delete.

As stated here: https://github.com/webui-dev/webui/issues/233#issuecomment-1738206193.

[...] Screenshot from 2023-09-28 00-44-42

Using firefox -CreateProfile gives some insight as it creates the profile in: “/home/parallels/snap/firefox/common/.mozilla/firefox/ui1hyf40.WebUI”. The location differs from logged location in the related issue: [Core] _webui_folder_exist([/home/parallels/.WebUI/WebUIFirefoxProfile])... After the command the WebUI profile is in the Profile List.

So it's probably the snap installed firefox(it's the ubuntu default browser) that needs to be covered.

ttytm commented 10 months ago

Sorry I need to correct myself.

When running firefox -CreateProfile "WebUI" /home/parallels/.WebUI/WebUIFirefoxProfile there are errors:

Failed to load module "canberra-gtk-module"

I installed the libcanberra-gtk-module and related packages but the issue remained. So I thought that installing it didn't make a difference.

But now just deleting the profile and running a WebUI app creates the Profile, despite that I still get the Failed to load module message. Before the profile wasn't created by webui. So it rather looks like it's a dependency issue in my case.

hassandraga commented 10 months ago

it's probably the snap installed firefox(it's the ubuntu default browser) that needs to be covered

Sure, we need to support Firefox snap version as well.

Failed to load module "canberra-gtk-module"

It's clear that it's an end-user issue, but we should implement the deletion of WebUI profile in the ini file.

hassandraga commented 10 months ago

I liked all your proposals @fibodevy. Still needs to be finished. https://github.com/webui-dev/webui/commit/2f694d1a3f7cf99269ba3a8843f4ff7425b9d2cd

hassandraga commented 9 months ago

Implemented (https://github.com/webui-dev/webui/commit/e462d7bfed87fd2a7e8883cb686d2e6a66791f04)

fibodevy commented 9 months ago

Good job 👍