我已经在Microsoft上安装了一个Chrome扩展来播放HLS视频。我试过微软的边缘(铬),它工作得很好。HLS是http://localhost/hls/taiguo/playlist.m3u8,在Microsoft浏览器上,它以如下方式显示URL:
当我使用WebView2将浏览器嵌入到开始使用WebView2 (开发人员预览)示例代码的Windows应用程序中时:
` CreateCoreWebView2EnvironmentWithDetails(nullptr,nullptr,nullptr,回调( hWnd -> 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的URL参数->导航(.)至:
webviewWindow->Navigate(L"extension://ekcifneimckhkjdfklkkpdlnckcjhmke/index.html#http://localhost/hls/taiguo/playlist.m3u8");
然后我得到一个错误消息,如下所示:应用程序屏幕捕获
我希望有人能告诉我如何使用WebView2 API运行扩展。
发布于 2020-05-10 07:41:40
我从事WebView2项目。首先,我要说WebView2目前不支持扩展。这是一个相当复杂的特性,我们需要做出很多设计选择,所以在解决这些问题之前,我们会故意关闭扩展。我们在未来一定会支持它,而且我们的反馈回购跟踪功能请求- https://github.com/MicrosoftEdge/WebViewFeedback/issues/81也存在一个问题。很高兴让您参与进来并讨论您的用例,所以我们有更多的上下文来说明您正在寻找什么。例如,开发人员为他们的应用程序启用任意的扩展(例如,我希望有一个广告阻止者监视我的web内容),我认为这与为最终用户提供在webview中安装扩展的方式有很大不同。
尽管如此,从技术角度来看,即使WebView2今天支持扩展,用户从浏览器安装的扩展也不会出现在WebView2中。浏览器将其扩展存储在其用户数据文件夹中(参见C:\Users_username_\AppData\Local\Microsoft\Edge SxS\User Data\Default\Extensions for Canary),该文件夹还包含cookies、缓存等内容。WebView2应用程序有自己的用户数据文件夹,由于安全性问题,无法使用浏览器用户数据。
https://stackoverflow.com/questions/61262830
复制相似问题