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

Question: WebView2 requires elevated mode ? #7190

Open
sigmarsson opened this issue Jun 5, 2022 · 21 comments
Open

Question: WebView2 requires elevated mode ? #7190

sigmarsson opened this issue Jun 5, 2022 · 21 comments
Labels
area-WebView product-winui3 WinUI 3 issues question team-Rendering Issue for the Rendering team

Comments

@sigmarsson
Copy link

Attempted to create and initialize WebView2 but Access Denied. This code is supposed to work only in elevated mode or a particular Windows policy required?

image

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Jun 5, 2022
@sigmarsson
Copy link
Author

Logged in as local administrator to windows but VS wasn't running as administrator.

@osamu-ikawa
Copy link

EnsureCoreWebView2Async seems to throw 0x80070005 when it can't create a user data folder.
Do you specify the path of the user data folder?

Reference:
MicrosoftEdge/WebView2Feedback#1128

@sigmarsson
Copy link
Author

How to specify UDF ? That example is missing on GitHub.

image

@sigmarsson
Copy link
Author

Access Denied even already at new CoreWebView2EnvironmentOptions();

I assume something like that shall be carried out for unpackaged products :

image

@osamu-ikawa
Copy link

In the WebView2 Win32 C ++ API, you can specify the path of the user data folder with the environment variable "WEBVIEW2_USER_DATA_FOLDER".

My app written in C++/WinRT and WinUI3 was able to specify a user data folder by calling the SetEnvironmentVariable function.

SetEnvironmentVariable(L"WEBVIEW2_USER_DATA_FOLDER", [Path to user data folder]);

However, as I reported in #7201, my app worked fine on Windows App SDK 1.0.3, but no longer works on machines with Windows App SDK 1.1.0 installed.

@sigmarsson
Copy link
Author

Cool, I am glad you succeeded to run the control . Yeah it smells a bit since in line 49 just attempted to invoke a default ctor. This param isn't necessary in your case.

@krschau
Copy link
Contributor

krschau commented Jun 10, 2022

@sigmarsson Creating custom environment options is not currently supported in WinUI. When you do need to specify a custom User Data Foder, @osamu-ikawa's suggestion of using the environment variable would be the way to do so at this point. Doing it directly via environment options is something we want to support in the future.

About the original issue: the Access Denied error is expected when you use a WebView2 inside a WinUI 3 unpackaged app. This is because the default location of the User Data Folder ends up being in a protected directory, and we can't create the folder there. Generally you'll want to handle the user data folder location and cleanup for this type of app. More details and guidance can be found in the Manage user data folders doc. Looks like we need to add a section to the "WinUI 3" tabs to give guidance for unpackaged apps -- I think it would look a lot like what's currently in the "Win32" tabs. I opened an issue to update the doc.

@osamu-ikawa
Copy link

@krschau
As mentioned in the comments above (#7190 (comment)), my WinUI3 unpackaged app used environment variables to set a custom user data folder and it worked fine with Windows App SDK 1.0.3.

However, after installing Windows App SDK 1.1.0, it stopped working properly.
I thought this was a bug in the Windows App SDK 1.1.0 and reported it in #7201, but the issue has already been closed.

I expect the custom data folder settings using environment variables to work even after installing Windows App SDK 1.1.X.

@sigmarsson
Copy link
Author

sigmarsson commented Jun 11, 2022

I confirm. 1.1.0 not working even having the variable set.

image

@castorix
Copy link

I confirm. 1.1.0 not working even having the variable set.

I get Access Denied on :

LoadLibraryExW( "C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.1_1000.516.2156.0_x86__8wekyb3d8bbwe\Microsoft.Web.WebView2.Core.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH )

So, if I copy Microsoft.Web.WebView2.Core.dll in my app directory, it works.
But this bug should be fixed asap...

@sigmarsson
Copy link
Author

@krschau
"Looks like we need to add a section to the "WinUI 3" tabs to give guidance for unpackaged apps"

Probably "unpackaged" scenario shall be the default one everywhere, everytime, since we all package after the product is done or at least RC. 1.1.2 ?

@sigmarsson
Copy link
Author

@krschau Which version can we expect the hotfix will ship and when ?

@krschau
Copy link
Contributor

krschau commented Jul 6, 2022

I can't reproduce the error -- I can use the environment variable to set a custom user data folder with no elevation using WinAppSDK 1.1.0. I too am logged in as admin, but not running VS in admin mode, although I agree with @HypsyNZ that it's probably a permissions thing, not elevation.

@sigmarsson I am seeing issues when I wait for EnsureCoreWebView2Async() as you did above, with t.AsTask().Wait(). Could you try just await this.WebView.EnsureCoreWebView2Async();? I wonder if the exception is really coming from the waiting.

Similarly, @castorix, could there be an issue with LoadLibraryExW? Are you saying the exception hit when you added that, or it was part of the call stack when you were debugging WebView2 creation?

@castorix
Copy link

castorix commented Jul 6, 2022

Similarly, @castorix, could there be an issue with LoadLibraryExW? Are you saying the exception hit when you added that, or it was part of the call stack when you were debugging WebView2 creation?

It is the error I saw by debugging : it could not load Microsoft.Web.WebView2.Core.dll with Access Denied error
While I have all rights to C:\Program Files\WindowsApps..., as I could copy Microsoft.Web.WebView2.Core.dll from there into the .exe directory and then it worked

@sigmarsson
Copy link
Author

image

@sigmarsson
Copy link
Author

sigmarsson commented Jul 7, 2022

image

@masaito505
Copy link

masaito505 commented Aug 4, 2022

Any progress on this issue?

In my unpackaged app, I get the 0x80070005 (Access denied) error when calling cookie manager API like below.

CoreWebView2().CookieManager().DeleteAllCookies();
CoreWebView2().CookieManager().AddOrUpdateCookie(cookie);

The 0x80070005 error happens with following backtrace.

D:\a\_work\1\s\dev\DynamicDependency\API\MddWinRT.cpp(54)\Microsoft.WindowsAppRuntime.dll!00007FFA80C4C592: (caller: 00007FFA80C2DCD3) ReturnHr(10) tid(5a0c) 80070005 Access denied.
    Msg:[D:\a\_work\1\s\dev\DynamicDependency\API\WinRTInprocModule.h(106)\Microsoft.WindowsAppRuntime.dll!00007FFA80C2771A: (caller: 00007FFA80C27857) Exception(3) tid(5a0c) 80070005 Access denied.
] 
D:\a\_work\1\s\dev\UndockedRegFreeWinRT\catalog.cpp(347)\Microsoft.WindowsAppRuntime.dll!00007FFA80C2DCF5: (caller: 00007FFA52A92817) ReturnHr(11) tid(5a0c) 80070005 Access denied.
D:\a\_work\1\s\dev\UndockedRegFreeWinRT\catalog.cpp(333)\Microsoft.WindowsAppRuntime.dll!00007FFA80C2DD35: (caller: 00007FFA52A92817) ReturnHr(12) tid(5a0c) 80070005 Access denied.
D:\a\_work\1\s\dev\UndockedRegFreeWinRT\urfw.cpp(246)\Microsoft.WindowsAppRuntime.dll!00007FFA80C2DD51: (caller: 00007FFA52A92817) ReturnHr(13) tid(5a0c) 80070005 Access denied.

The issue happens only when I use WinAppSDK 1.1.x and doesn't happen when I use WinAppSDK 1.0.x.
So I think this is caused by same UDF permission related issue of WinAppSDK 1.1.

@lyahdav
Copy link

lyahdav commented Nov 22, 2022

I just tried to repro this in an unpackaged WinUI 3 app using the latest WinAppSDK 1.2.221109.1 and setting the WEBVIEW2_USER_DATA_FOLDER environment variable, and I think I'm still able to repro this bug. In my case it renders a blank page. Here's a repo where it repros: https://github.com/lyahdav/MyWebView2WinUI3-2.

@sigmarsson
Copy link
Author

Package jor app with the template studio to get all this immediate running. Unpackaged application supported but with a pinch of salt merely. Not worth spending the time .

@bpulliam bpulliam removed the needs-triage Issue needs to be triaged by the area owners label Dec 7, 2022
@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@lyahdav
Copy link

lyahdav commented Jul 28, 2023

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Per my previous comment this still seems to be an issue even when setting the WEBVIEW2_USER_DATA_FOLDER environment variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-WebView product-winui3 WinUI 3 issues question team-Rendering Issue for the Rendering team
Projects
None yet
Development

No branches or pull requests

9 participants