gpt4 book ai didi

c++ - 如何在 WebView2 上启用扩展

转载 作者:行者123 更新时间:2023-12-01 14:39:34 29 4
gpt4 key购买 nike

我在 Microsoft Edge (Chromium) 上安装了 Chrome 扩展程序来播放 HLS 视频。我已经尝试过 Microsoft Edge (Chromium),它运行良好。 HLS URL 是 http://localhost/hls/taiguo/playlist.m3u8在 Microsoft Edge 浏览器上,它会显示如下 URL:extension://ekcifneimckhkjdfklkkpdlnckcjhmke/index.html# http://localhost/hls/taiguo/playlist.m3u8 .

当我按照 [WebView2 入门(开发者预览版)](https://learn.microsoft.com/en-us/microsoft-edge/hosting/webview2/gettingstarted)示例代码使用 WebView2 将浏览器嵌入 Windows 应用程序时:

` CreateCoreWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr, 打回来( [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 文件而不播放视频。如果我将 webviewWindow->Navigate(...) 的 URL 参数更改为:

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

然后我收到如下所示的错误消息: App screen capture

我希望有人能告诉我如何使用 WebView2 API 运行扩展。

最佳答案

我从事 WebView2 项目。首先让我说 WebView2 目前不支持扩展。这是一个相当复杂的功能,我们必须做出很多设计选择,所以在解决这些问题之前,我们特意关闭了扩展。我们绝对愿意在未来支持它,我们的反馈 repo 跟踪功能请求存在问题 - https://github.com/MicrosoftEdge/WebViewFeedback/issues/81 .很高兴您能插话并谈论您的用例,这样我们就可以了解您正在寻找的内容。例如,开发人员为他们的应用程序启用任意扩展(例如,我想让一个广告拦截器监视我的网络内容),我认为这就是你要问的,这与为最终用户提供一种安装扩展的方法非常不同 WebView 。

也就是说,从技术角度来看,即使 WebView2 今天支持扩展,用户从浏览器安装的扩展也不会显示在 WebView2 中。浏览器将其扩展存储在其用户数据文件夹中(请参阅 C:\Users\用户名\AppData\Local\Microsoft\Edge SxS\User Data\Default\Extensions for Canary),其中还包含诸如cookie、缓存等。WebView2 应用程序有自己的用户数据文件夹,并且由于安全隐患而无法使用浏览器用户数据。

关于c++ - 如何在 WebView2 上启用扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61262830/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com