WebView2’s ICoreWebView2CreateCoreWebView2ControllerCompletedHandler callback is never called when the process is running in a login screen

  Kiến thức lập trình

I need to use the WebView2 control from a custom credential provider, written in C++. I’m using MSFT’s Win32_GettingStarted sample as a test. I can build it in VS 2022 and it runs fine in a regular user desktop.

But if I use the same code from a custom credential provider (that runs in a secure desktop in the login screen) the WebView2 control remains blank. I did some investigation and was able to see that in the following test code snippet:

void CreateWebView(HWND hWnd)
{
    HRESULT hr;
    WCHAR buff[256];

    //Get temp folder
    WCHAR buffTmp[MAX_PATH] = {};
    GetTempPath(_countof(buffTmp), buffTmp);
    StringCchCat(buffTmp, _countof(buffTmp), L"WebView2GettingStarted\");
    g_strTmpPath = buffTmp;

    // <-- WebView2 sample code starts here -->
    // Step 3 - Create a single WebView within the parent window
    // Locate the browser and set up the environment for WebView
    hr = CreateCoreWebView2EnvironmentWithOptions(nullptr, buffTmp, nullptr,
        Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
            [hWnd](HRESULT result, ICoreWebView2Environment* env) -> HRESULT 
            {
                HRESULT hr2;

                // Create a CoreWebView2Controller and get the associated CoreWebView2 whose parent is the main window hWnd
                hr2 = env->CreateCoreWebView2Controller(hWnd, 
                    Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
                    [hWnd](HRESULT result, ICoreWebView2Controller* controller) -> HRESULT
                    {
                        HRESULT hr;

                        MessageBox(
                            NULL, L"ICoreWebView2CreateCoreWebView2ControllerCompletedHandler was called", 
                                                        L"Loaded_MsgBox",
                            MB_OK);

                        //Other code
                        ....

                        return S_OK;
                    }).Get());


                if(FAILED(hr2))
                {
                    WCHAR buff[256] = {};
                    StringCchPrintf(buff, _countof(buff), L"ERROR: (0x%x) CreateCoreWebView2Controller", hr2);
                    MessageBox(NULL, buff, L"ERROR", MB_ICONERROR);
                }


                return S_OK;
            }).Get());


    if(FAILED(hr))
    {
        StringCchPrintf(buff, _countof(buff), L"ERROR: (0x%x) CreateCoreWebView2EnvironmentWithOptions", hr);
        MessageBox(NULL, buff, L"ERROR", MB_ICONERROR);
    }

    return hr;
}

The env->CreateCoreWebView2Controller call succeeds, but the ICoreWebView2CreateCoreWebView2ControllerCompletedHandler callback is never invoked (or my "Loaded_MsgBox" is never shown), so the HWND for the WebView2 remains blank.

There seems to be no error messages or anything that I can find.

Moreover, when I close the process, this also causes a crash somewhere in the destructor in the EmbeddedBrowserWebView.dll.

The WebView2 itself is so huge, I don’t even know where to begin approaching this. Plus finding something that is never called is always hard.

Anyone who is familiar with the WebView2, do you have any idea how to make it work from the secure desktop?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT