dolphinsmalltalk / Dolphin

Dolphin Smalltalk Core Image
MIT License
301 stars 58 forks source link

Win32 errors when trying to use WebView2 #1162

Closed JBetz closed 2 years ago

JBetz commented 2 years ago

I'm trying to use the new WebView2 package and unable to get it working.

I installed the runtime from https://developer.microsoft.com/en-US/microsoft-edge/, restarted my computer, and copied WebView2Loader.dll from this repo into my Dolphin application directory (C:\Program Files (x86)\Dolphin Smalltalk 7). But the example code still fails, displaying a message about how I still need to download the runtime.

wv := URLPresenter show: 'WebView2'.
wv value: 'https://github.com/DolphinSmalltalk/Dolphin'

Inspecting the Win32Error shows that the first time I run it I get a generic "Access denied" error, then all subsequent attempts I get a GPFault ("Invalid access to memory location").

I checked the file permissions of the DLL but as far as I can tell they are correct and identical to the other DLLs in the same folder that are working. Then again, I remember having access issues whenever adding new DLLs, so perhaps there's a step I've forgotten? I also tried copying the DLL to the same directory as the image file but that had the same result.

JBetz commented 2 years ago

Okay, I worked the problem.

The "Access denied" error wasn't referring to Dolphin's attempt to use the DLL but rather internal to WebView2 when it tries to access the User Data Folder, which by default is created in the same directory as the executable.

I created a folder named Dolphin7.exe.WebView2 inside of C:\Program Files (x86)\Dolphin Smalltalk 7, then another named EBWebView inside of that. And now finally I can see the web page.

If I recall correctly, this was the same problem I had with a different DLL that had to create a folder for its own database.

So now my question is, how do I setup Dolphin such that DLLs have write permissions to the directory of the executable? Do I have to copy the Dolphin7.exe file to a more permissive folder?

In this specific case, I think the right solution is to implement CreateCoreWebView2EnvironmentWithOptions so the User Data Folder location can be specified, but either way, I'd like to know whether there is something generally wrong with my setup and/or the default Dolphin setup.

blairmcg commented 2 years ago

Thanks for reporting the issue Joe. I'd not experienced this because I don't use the setup. As I'm always building everything from source, my Dolphin.exe is within my working tree, and therefore in a writable folder. I had noticed that webview2 creates the user data directory in a sub-folder of the application exe's folder because I had to add a .gitignore filter for it, but it hadn't registered with me that this would mean it would always fail for any application installed by a standard kind of setup into the program files hierarchy (doh!).

In this specifically case, I think the right solution is to implement CreateCoreWebView2EnvironmentWithOptions so the User Data Folder location can be specified, but either way, I'd like to know whether there is something generally wrong with my setup and/or the default Dolphin setup.

It's not indicative of an issue with the setup, or your own setup. The default placement of the webview2 user data folder is not really a good choice given that applications should (for security reasons) be installed to folders that are not writable with normal user privileges. However, given this odd default choice, then as you suggest the correct solution is to implement the environment options to place the folder somewhere more sensible, like %LocalAppData%