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

WebView does not display the content in ~5% of runs #1975

Open
DmitryKorepanov opened this issue Nov 30, 2021 · 4 comments
Open

WebView does not display the content in ~5% of runs #1975

DmitryKorepanov opened this issue Nov 30, 2021 · 4 comments
Assignees
Labels
bug Something isn't working priority-low We have considered this issue and decided that we will not be able to address it in the near future. tracked We are tracking this work internally.

Comments

@DmitryKorepanov
Copy link

DmitryKorepanov commented Nov 30, 2021

Description
Hi! I use Fixed Version WebView in Win32 application.
It usually works fine. But in ~5% of application runs, the WebView does not display the content.
Usually, 8 msedgewebview2.exe processes are created on the system to service WebView control. But in those 5% of cases when the WebView content is not displayed, there are only 4 or 5 processes.
Crashpad\reports is empty.
Event Log is empty.
ProcessFailed event does not happen.

What could be the problem? Are there any tools for debugging?

Usage sample:

	auto options = Make<CoreWebView2EnvironmentOptions>();
	checkHRESULT( options->put_AdditionalBrowserArguments( L"--disable-features=msSmartScreenProtection" ) );
	checkHRESULT( CreateCoreWebView2EnvironmentWithOptions( runtimePath, userDataPath, options.Get(),
		Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>( this, &CWebView::OnCreateEnvironmentCompleted ).Get() ) );

	// Pseudo-synchronous creation https://github.com/MicrosoftEdge/WebView2Feedback/issues/740
	while( webviewWindow == nullptr && ::WaitMessage() ) {
		CMessageLoop::PumpMessages( 0, WM_USER + 1, WM_USER + 1 );
	}

	checkHRESULT( webviewWindow->add_ProcessFailed(
		Callback<ICoreWebView2ProcessFailedEventHandler>( this, &CWebView::OnProcessFailed ).Get(), &processFailedToken ) );

	CComPtr<ICoreWebView2Settings> settings;
	checkHRESULT( webviewWindow->get_Settings( &settings ) );
	checkHRESULT( settings->put_IsZoomControlEnabled( FALSE ) );
	checkHRESULT( settings->put_IsStatusBarEnabled( FALSE ) );
	checkHRESULT( settings->put_AreDefaultContextMenusEnabled( FALSE ) );
	checkHRESULT( settings->put_AreDevToolsEnabled( FALSE ) );

	checkHRESULT( controller->put_Bounds( rect ) );

	checkHRESULT( webviewWindow->Navigate( url ) );

Version
SDK: 1.0.1020.30
Runtime: 95.0.1020.53
Framework: Win32
OS: Win10

AB#37316750

@champnic
Copy link
Member

champnic commented Dec 1, 2021

Hey @DmitryKorepanov - the biggest thing that jumps out is the message pump to try and achieve synchronous initialization. In the cases where nothing shows up, can you confirm that it gets past the message pump?

@champnic champnic self-assigned this Dec 1, 2021
@DmitryKorepanov
Copy link
Author

Yes, the execution goes through message pump loop and application does not freeze.
Webview looks as if it was forgotten to show.

@champnic champnic added bug Something isn't working tracked We are tracking this work internally. and removed question labels Dec 7, 2021
@champnic
Copy link
Member

champnic commented Dec 7, 2021

I've added this as a bug on our backlog. Thanks!

@github-actions github-actions bot added the priority-low We have considered this issue and decided that we will not be able to address it in the near future. label Mar 26, 2024
@Kretikus
Copy link

We are running in a similiar issue. Our application can open multiple WebView2 Embedded Windows and sometimes the windows are gray and apear to be not initialized correctly, but there is no error return code.
If we comment out the put_Bounds call below, the resulting window looks the same.
Could it be that the put_Bounds call is at a wrong place?

Here is our initialization code:

bool WebViewImpl::Init(CWnd* wnd, const INString& url, CWnd* /*parent*/)
{
  HWND hWnd = wnd->GetSafeHwnd();

  LPWSTR edgeVersion;
  GetAvailableCoreWebView2BrowserVersionString(nullptr, &edgeVersion);
  if (edgeVersion) {
    const auto verStr = INString::fromUnicode(edgeVersion);
    LOG_INFO(_T("Edge version: %%1"), verStr);
    CoTaskMemFree(edgeVersion);
  }

  WebViewImpl* impl = this;

  const HRESULT createEnvRet =
  CreateCoreWebView2EnvironmentWithOptions(nullptr, nullptr, nullptr,
  Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
    [hWnd, impl, url](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {

      // Create a CoreWebView2Controller and get the associated CoreWebView2 whose parent is the main window hWnd
      const HRESULT createControllerRet =
      env->CreateCoreWebView2Controller(hWnd, Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
        [hWnd, impl, url](HRESULT result, ICoreWebView2Controller* controller) -> HRESULT {
          if (controller != nullptr) {
            impl->webviewController = controller;
            impl->webviewController->get_CoreWebView2(&(impl->webviewWindow));
          }

          // Add a few settings for the webview
          // The demo step is redundant since the values are the default settings
          ICoreWebView2Settings* Settings;
          impl->webviewWindow->get_Settings(&Settings);
          Settings->put_IsScriptEnabled(TRUE);
          Settings->put_AreDefaultScriptDialogsEnabled(TRUE);
          Settings->put_IsWebMessageEnabled(TRUE);
#ifdef DEBUG
          Settings->put_AreDevToolsEnabled(TRUE);
#else
          Settings->put_AreDevToolsEnabled(FALSE);
#endif

          // Resize WebView to fit the bounds of the parent window
          RECT bounds;
          GetClientRect(hWnd, &bounds);
          [[maybe_unused]] const auto boundsRet = impl->webviewController->put_Bounds(bounds);
          INASSERT(boundsRet == S_OK);

          // Schedule an async task to navigate to Bing
          impl->webviewWindow->Navigate(url.toWstring().c_str());

          return S_OK;
        }).Get());
      if (createControllerRet != S_OK) {
        LOG_ERROR(_T("Could not initialize WebView2 Controller. CreateCoreWebView2Controller failed with: %%1. Msg: %%2"), createControllerRet, ErrorDescription(createControllerRet));
      }
      return S_OK;
    }).Get());

  if (createEnvRet != S_OK) {
    LOG_ERROR(_T("Could not initialize WebView2. CreateCoreWebView2EnvironmentWithOptions failed with: %%1. Msg: %%2"), createEnvRet, ErrorDescription(createEnvRet));
  }

  return createEnvRet == S_OK;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-low We have considered this issue and decided that we will not be able to address it in the near future. tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

3 participants