Как включить расширение на WebView2 - PullRequest
0 голосов
/ 17 апреля 2020

Я установил расширение Chrome в Microsoft Edge (Chromium) для воспроизведения видео HLS. Я пробовал на Microsoft Edge (Chromium), и он отлично работает. URL-адрес HLS http://localhost/hls/taiguo/playlist.m3u8 и в браузере Microsoft Edge отображает URL-адрес следующим образом: extension: //ekcifneimckhkjdfklkkpdlnckcjhmke/index.html#http://localhost/hls/taiguo/playlist.m3u8.

Когда я использую WebView2 для встраивания браузера в приложение Windows, следуя [Приступая к работе с WebView2 (предварительный просмотр разработчика)]] (https://docs.microsoft.com/en-us/microsoft-edge/hosting/webview2/gettingstarted) пример кода:

`CreateCoreWebView2EnvironmentWithDetails ( nullptr, nullptr, nullptr, Callback ([hWnd] (результат HRESULT, ICoreWebView2Environment * env) -> HRESULT {

    RETURN_IF_FAILED(result);
    // Create a CoreWebView2Host and get the associated CoreWebView2 whose parent is the main window hWnd
    env->CreateCoreWebView2Host(hWnd, Callback<ICoreWebView2CreateCoreWebView2HostCompletedHandler>(
        [hWnd](HRESULT result, ICoreWebView2Host* host) -> HRESULT {
        if (host != nullptr) {
            webviewHost = host;
            webviewHost->get_CoreWebView2(&webviewWindow);
        }

        // Add a few settings for the webview
        // this is a redundant demo step as they are the default settings values
        ICoreWebView2Settings* Settings;
        webviewWindow->get_Settings(&Settings);
        Settings->put_IsScriptEnabled(TRUE);
        Settings->put_AreDefaultScriptDialogsEnabled(TRUE);
        Settings->put_IsWebMessageEnabled(TRUE);

        // Resize WebView to fit the bounds of the parent window
        RECT bounds;
        GetClientRect(hWnd, &bounds);
        webviewHost->put_Bounds(bounds);

        // Schedule an async task to navigate to Bing
        webviewWindow->Navigate(L"http://localhost/hls/taiguo/playlist.m3u8");`

Если я запускаю приведенный выше код, приложение просто загрузит файл playlist.m3u8 без Воспроизведение видео. Если я изменю параметр URL webviewWindow-> Navigate (...) на:

webviewWindow->Navigate(L"extension://ekcifneimckhkjdfklkkpdlnckcjhmke/index.html#http://localhost/hls/taiguo/playlist.m3u8");

Затем я получаю сообщение об ошибке, как показано ниже: Снимок экрана приложения

Надеюсь, кто-нибудь подскажет, как запустить расширение с помощью API WebView2.

...