Skip to content
/ WebView2Feedback Public
  • Notifications You must be signed in to change notification settings
  • Fork 53
  • Star 441
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.

Sign up for GitHub

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

Jump to bottom

我觉得我在使用webview2的过程中遇到了一个bug,关于在C盘中运行 代码或者执行编译好的应用程序 #3087

Closed
Naylor55 opened this issue Dec 27, 2022 · 9 comments
Closed

我觉得我在使用webview2的过程中遇到了一个bug,关于在C盘中运行 代码或者执行编译好的应用程序 #3087

Naylor55 opened this issue Dec 27, 2022 · 9 comments
Assignees
@novac42
Labels
bug Something isn't working

Comments

@Naylor55
Copy link

Naylor55 commented Dec 27, 2022

Description
创建一个WPF的应用程序,引入webview2控件来显示网页,当代码放到E盘(E:\code\WPF\WebView2Bug)的时候应用程序启动后webview2控件成功显示了网页信息,但是当将代码文件放到C盘(C:\Program Files (x86)\WebView2Bug)中的时候,此时应用启动之后webview2控件显示空白,调试的时候,webview2.corewebview2对象为null

Version
我开发环境用的windows11,VS的版本为Microsoft Visual Studio Community 2022 (64 位) - Current
版本 17.4.1,webview2的版本为1.0.1418.22

Repro Steps
核心代码如下 :
xaml:

<Window x:Class="WebView2Bug.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
        xmlns:local="clr-namespace:WebView2Bug"
        mc:Ignorable="d"
        Title="MainWindow" Height="950" Width="1300" ContentRendered="Window_ContentRendered">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="60"></RowDefinition>
            <RowDefinition Height="10*"></RowDefinition>
        </Grid.RowDefinitions>
        <Button Grid.Row="0" Name="btn" Width="100" Height="50" Content="查看CoreWebview2" Click="btn_Click"></Button>
        <wv2:WebView2 Grid.Row="1" Name="browser"   Source="http://baidu.com"/>

    </Grid>
</Window>

cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WebView2Bug
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_ContentRendered(object sender, EventArgs e)
        {
            
        }

        private void btn_Click(object sender, RoutedEventArgs e)
        {
            bool result = this.browser.CoreWebView2 == null ? true : false;
            MessageBox.Show("WebView2控件的CoreWebView2是否为null?" + result);
        }
    }
}


Screenshots

当代码在E盘(E:\code\WPF\WebView2Bug)中的时候,程序运行起来可以正常显示网页信息:

图片

当点击 查看CoreWebView 按钮的时候,获取到其值不为null:
图片

当代码在C盘(C:\Program Files (x86)\WebView2Bug)中 的时候,程序运行起来不可以显示网页信息:
图片

当点击 查看CoreWebView 按钮的时候,获取到其值为null:
图片

Additional context

复现和演示代码: https://github.com/Naylor55/WebVeiw2BugFeedback

当将编译好的wpf程序使用 InnoSetup 打包并安装到客户机 C盘的时候,Webview2 控件无法显示网页信息,当安装到客户机非C盘的时候,Webview2控件可以正常显示网页信息

@Naylor55 Naylor55 added the bug Something isn't working label Dec 27, 2022
@victorthoang victorthoang assigned novac42 Dec 27, 2022
@victorthoang
Copy link

victorthoang commented Dec 27, 2022

Hello @Naylor55,

Thanks for your bug report. I've assigned this to a dev that can best try to replicate the issue and follow up on this. With holidays over and new year's approaching, I appreciate your patience!

@sln162
Copy link

sln162 commented Dec 27, 2022

@Naylor55
image
隐式初始化(Source="http://baidu.com"),和显示初始化不指定userDataFolder,都会在软件位置生成UDF文件夹,如图。
C盘遇到权限文件太正常了,毕竟WebView2不以管理员权限运行,就算把你的程序用管理员运行也是一样,它会降权(为了安全性),所以在这个位置的文件夹WebView2没操作权限。

我不知道官方会不会认为是个BUG,但我知道怎么解决,只需要用显示初始化(EnsureCoreWebView2Async),并设置userDataFolder文件夹到一个不需要权限的位置。

@Naylor55
Copy link
Author

Naylor55 commented Dec 27, 2022

@victorthoang @sln162 感谢及时的回复和提供解决方案,我今天用另外一个方案解决了,程序启动的时候为xxx.WebView2文件夹追加Everyone的写入权限,您提供的这个方案我明天上班了会尝试。



        /// <summary>
        /// 给 WebView2Bug.exe.WebView2 文件夹赋予写入权限
        /// </summary>
        private void InitWebView2DirAccess()
        {
            try
            {
                string path = AppDomain.CurrentDomain.BaseDirectory;
                string webview2DataDir = path + "WebView2Bug.exe.WebView2";
                DirectoryInfo dir = new DirectoryInfo(webview2DataDir);
                System.Security.AccessControl.DirectorySecurity security = dir.GetAccessControl();
                //给文件夹追加 Everyone 的写入权限
                security.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule("Everyone", System.Security.AccessControl.FileSystemRights.Write, AccessControlType.Allow));
                dir.SetAccessControl(security);
            }
            catch (Exception ex)
            {
                string  msg = ex.Message;
            }
        }

@Naylor55 Naylor55 closed this as completed Dec 28, 2022
@Naylor55
Copy link
Author

Naylor55 commented Dec 28, 2022

两种方法都可以解决

@Naylor55 Naylor55 reopened this Dec 28, 2022
@Naylor55 Naylor55 closed this as completed Dec 28, 2022
@sln162
Copy link

sln162 commented Jan 2, 2023

@Naylor55 你的增加权限的解决方案很有趣,我也受到了启发。但如果增加Users用户的FullControl权限,会不会更合适点?创建文件夹的权限应该是AppendData权限,所以安全起见应该是FullControl权限,但Everyone是不是太偏激了,设置Users的FullControl权限是否也能满足要求? 我在增加这个方案作为备用方案,因为发现有些用户即使AppData文件夹也会出现奇怪的权限问题。
@novac42 对此如何选择,你们有任何建议吗?谢谢

@novac42
Copy link
Contributor

novac42 commented Jan 5, 2023

@sln162 好问题,我记录下来跟技术团队讨论一下。同意把Everyone缩小到Users会更可控,我们也看看有没有更好的方案。- Good question, I'm gonna need to discuss with the dev team to see what an ideal solution would be and get back to you.

@sln162
Copy link

sln162 commented Jan 5, 2023

@novac42 谢谢回应,目前针对灾难性故障0x8000FFFF和拒绝访问0x80070005做了此处理,目前观察,大部分都在二次初始化完成,还有一部分执行完此方案仍然无法初始化,这部分可能不是权限问题。期待官方团队有更好的方案。- Thank you for your response. At present, this process has been done for catastrophic failure 0x8000FFFF and access denial 0x80070005. According to current observations, most of them are completed in the second initialization, and some of them still cannot be initialized after executing this solution. This part may not be a permission problem. Looking forward to the official team has a better plan.

@Naylor55
Copy link
Author

Naylor55 commented Jan 29, 2023

@Naylor55 你的增加权限的解决方案很有趣,我也受到了启发。但如果增加Users用户的FullControl权限,会不会更合适点?创建文件夹的权限应该是AppendData权限,所以安全起见应该是FullControl权限,但Everyone是不是太偏激了,设置Users的FullControl权限是否也能满足要求? 我在增加这个方案作为备用方案,因为发现有些用户即使AppData文件夹也会出现奇怪的权限问题。 @novac42 对此如何选择,你们有任何建议吗?谢谢

对的,仅增加Users的权限确实是更好的方案,并且需要考虑当某些用户是以管理员身份登录的时候Users是否起作用。我提供的示例代码仅仅是为了表达这个处理思路。

@LostAsk LostAsk mentioned this issue May 4, 2023
部分win10系统 webview2控件白屏 #3455
Closed
@minchen123
Copy link

minchen123 commented Sep 14, 2024

使用 InnoSetup 打包,在C盘部署的话,增加E:\code\WPF\WebView2Bug.exe.WebView2权限的同时,也必须要给打的包赋予管理员权限才可以

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants
@minchen123 @novac42 @sln162 @Naylor55 @victorthoang

Footer

© 2024 GitHub, Inc.

玻璃钢生产厂家新疆艺术玻璃钢雕塑做玻璃钢雕塑哪家服务好德州不锈钢仿古玻璃钢景观雕塑玻璃钢景观雕塑供应商苏州玻璃钢雕塑费用周口卡通玻璃钢雕塑玻璃钢雕塑易燃湖北仿铜玻璃钢雕塑批发东丽玻璃钢雕塑工程玻璃钢小和尚雕塑云南玻璃钢雕塑厂打磨工招聘江苏特色玻璃钢雕塑生产厂家朔州玻璃钢仿铜雕塑定制供应惠州定制玻璃钢面包雕塑贵州兴义玻璃钢雕塑厂家特色玻璃钢雕塑摆件销售公司蚌埠步行街玻璃钢雕塑东兴玻璃钢雕塑潢川玻璃钢雕塑河南景观玻璃钢雕塑图片辽宁玻璃钢雕塑加工玻璃钢雕塑中式上海中庭商场美陈采购温州抽象玻璃钢雕塑市场西游记玻璃钢雕塑图片广东欧式玻璃钢雕塑定制浙江大型商场美陈研发广东商场主题创意商业美陈费用文山玻璃钢雕塑厂家深圳开业商场美陈销售公司香港通过《维护国家安全条例》两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”19岁小伙救下5人后溺亡 多方发声单亲妈妈陷入热恋 14岁儿子报警汪小菲曝离婚始末遭遇山火的松茸之乡雅江山火三名扑火人员牺牲系谣言何赛飞追着代拍打萧美琴窜访捷克 外交部回应卫健委通报少年有偿捐血浆16次猝死手机成瘾是影响睡眠质量重要因素高校汽车撞人致3死16伤 司机系学生315晚会后胖东来又人满为患了小米汽车超级工厂正式揭幕中国拥有亿元资产的家庭达13.3万户周杰伦一审败诉网易男孩8年未见母亲被告知被遗忘许家印被限制高消费饲养员用铁锨驱打大熊猫被辞退男子被猫抓伤后确诊“猫抓病”特朗普无法缴纳4.54亿美元罚金倪萍分享减重40斤方法联合利华开始重组张家界的山上“长”满了韩国人?张立群任西安交通大学校长杨倩无缘巴黎奥运“重生之我在北大当嫡校长”黑马情侣提车了专访95后高颜值猪保姆考生莫言也上北大硕士复试名单了网友洛杉矶偶遇贾玲专家建议不必谈骨泥色变沉迷短剧的人就像掉进了杀猪盘奥巴马现身唐宁街 黑色着装引猜测七年后宇文玥被薅头发捞上岸事业单位女子向同事水杯投不明物质凯特王妃现身!外出购物视频曝光河南驻马店通报西平中学跳楼事件王树国卸任西安交大校长 师生送别恒大被罚41.75亿到底怎么缴男子被流浪猫绊倒 投喂者赔24万房客欠租失踪 房东直发愁西双版纳热带植物园回应蜉蝣大爆发钱人豪晒法院裁定实锤抄袭外国人感慨凌晨的中国很安全胖东来员工每周单休无小长假白宫:哈马斯三号人物被杀测试车高速逃费 小米:已补缴老人退休金被冒领16年 金额超20万

玻璃钢生产厂家 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化