Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How can I adapt this code to use put_ChannelSearchKind instead of a folder when initialising with Win32? #5055

Open
ajtruckle opened this issue Jan 25, 2025 · 4 comments

Comments

@ajtruckle
Copy link

ajtruckle commented Jan 25, 2025

@ajtruckle You might just need to point your app to use the Canary WebView2 by following steps here. Initialize your webview2 with CoreWebView2EnvironmentOptions.ChannelSearchKind

Originally posted by @pushkin- in #1737

I would like to adapt my code to use this concept. At the moment I have:

void CWebBrowser::InitializeWebView()
{
	CloseWebView();

	CString subFolder = GetInstallPath();
	CString appData = GetUserDataFolder();

	auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
	CHECK_FAILURE(options->put_AdditionalBrowserArguments(L"--allow-file-access-from-files"));

	HRESULT hr = CreateCoreWebView2EnvironmentWithOptions(
		subFolder,
		appData,
		options.Get(),
		Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
			this,
			&CWebBrowser::OnCreateEnvironmentCompleted).Get());

	if (!SUCCEEDED(hr))
	{
		CString text;
		if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
		{
			text = L"Cannot found the WebView2 component.";
		}
		else
		{
			text = L"Cannot create the webview environment.";
		}

		ShowFailure(hr, text);
	}
}

I am not sure how to tweak this to use the put_ChannelSearchKind(COREWEBVIEW2_CHANNEL_SEARCH_KIND value) property instead of the folder.

I want to temporarily set it to COREWEBVIEW2_CHANNEL_SEARCH_KIND_LEAST_STABLE.

@ajtruckle
Copy link
Author

I have downloaded the latest samples and done a full search for how to use this property. It is not used in any code.

@ajtruckle
Copy link
Author

OK, I think the docs might be out of date? This is exposed in my IDE:

options->put_ChannelSearchKind(COREWEBVIEW2_CHANNEL_SEARCH_KIND_LEAST_STABLE);

But again, how do we safely remove the use of subFolder?

@ajtruckle
Copy link
Author

Doesn't make sense to me. I adjusted my code to set the search code and I passed null for the folder argument:

void CWebBrowser::InitializeWebView()
{
	CloseWebView();

	CString subFolder = GetInstallPath();
	CString appData = GetUserDataFolder();

	auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
	CHECK_FAILURE(options->put_AdditionalBrowserArguments(L"--allow-file-access-from-files"));
	CHECK_FAILURE(options->put_ChannelSearchKind(COREWEBVIEW2_CHANNEL_SEARCH_KIND_MOST_STABLE));
	//CHECK_FAILURE(options->put_ChannelSearchKind(COREWEBVIEW2_CHANNEL_SEARCH_KIND_LEAST_STABLE));
	HRESULT hr = CreateCoreWebView2EnvironmentWithOptions(
		nullptr,
		appData,
		options.Get(),
		Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
			this,
			&CWebBrowser::OnCreateEnvironmentCompleted).Get());

	if (!SUCCEEDED(hr))
	{
		CString text;
		if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
		{
			text = L"Cannot found the WebView2 component.";
		}
		else
		{
			text = L"Cannot create the webview environment.";
		}

		ShowFailure(hr, text);
	}
}

In my tests:

  • CHECK_FAILURE(options->put_ChannelSearchKind(COREWEBVIEW2_CHANNEL_SEARCH_KIND_MOST_STABLE));

    • Webview2 Runtime Version: 131.0.2903.146
    • Webview2 SDK Build: 2957.106
  • CHECK_FAILURE(options->put_ChannelSearchKind(COREWEBVIEW2_CHANNEL_SEARCH_KIND_LEAST_STABLE));

    • Webview2 Runtime Version: 131.0.2903.146
    • Webview2 SDK Build: 2957.106

No matter what I try, it still seems to use my stable runtime and not the Canary Edge ...

@ajtruckle
Copy link
Author

Besides, when I do try to use the experimental features I get a popup saying the browser I am using does not support them.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant