Cefsharp chromium 浏览器不会仅在 Windows 服务器 2012 上第一次加载

Cefsharp chromium browser doesn't load only first time on Windows server 2012

您好,我有 wpf 桌面应用程序。我正在使用 cefsharp.wpf chromium 浏览器打开网页。我从 nuget pacakge 管理器(版本 87.1.132)添加了 cefsharp。它在我的系统中运行良好(Windows 10、64 位 os)。

但是当我在客户端环境中 运行 我的 exe (windows 2012 r2,64 位 os) 时,奇怪的事情发生了,即只有当我第一次尝试。基本上我有一个按钮,点击按钮我打开一个 window,里面有 cefsharp chromium 浏览器。所以当 window 第一次打开时浏览器不会加载任何东西。现在,如果我 close window 并再次打开它,浏览器将重定向到我的 url 。只有第一次浏览器不加载。第一次后它每次都会加载,直到我 close exe 并重试。

如果我 close exe 并再次打开它并尝试打开 window,浏览器将再次加载任何内容。然后我 close window 并重试浏览器将完美运行。

我做的事情很简单,我在 xaml 文件中有一个 window 浏览器,在加载 window 时在 cs 文件中,我正在为浏览器分配一个地址,并且就是这样。

在xaml <cefSharp:ChromiumWebBrowser x:Name="browser" />

在 xaml.cs 上 window 加载

browser.address = url; // 我正在使用 www.xero.com 登录 url(我认为这不重要,因为它第二次起作用了)。

谁能告诉我这里发生了什么?

我有 cefsharp 的 debug.log 文件,上面写着:

[0317/231700.441:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale 
[0317/231700.442:ERROR:alloy_main_delegate.cc(539)] Could not load locale pak for en-US
[0317/231700.537:ERROR:viz_main_impl.cc(150)] Exiting GPU process due to errors during initialization
[0317/231700.542:ERROR:browser_gpu_channel_host_factory.cc(168)] Failed to launch GPU process.
[0317/232456.104:WARNING:resource_bundle.cc(1086)] locale resources are not loaded
[0317/232456.105:WARNING:resource_bundle.cc(1086)] locale resources are not loaded
[0317/232456.421:WARNING:resource_bundle.cc(431)] locale_file_path.empty() for locale 
[0317/232456.422:ERROR:alloy_main_delegate.cc(539)] Could not load locale pak for en-US
[0317/232458.805:INFO:CONSOLE(333)] "Refused to connect to 'https://analytics.google.com/g/collect?v=2&tid=G-Q622B96ZEQ&gtm=2oe330&_p=609855886&sr=1366x768&_gaz=1&ul=en-us&cid=1821054078.1615983899&_s=1&dl=https%3A%2F%2Flogin.xero.com%2Fidentity%2Fuser%2Flogin%3FReturnUrl%3D%252Fidentity%252Fconnect%252Fauthorize%252Fcallback%253Fresponse_type%253Dcode%2526client_id%253DC35C4505FBEA4D31A8E5A0404FDA9E0E%2526redirect_uri%253Dhttp%25253A%25252F%25252Flocalhost%2526scope%253Dopenid%252520profile%252520email%252520files%252520accounting.transactions%252520accounting.tra...2520accounting.journals.read%252520accounting.settings%252520accounting.settings.read%252520accounting.contacts%252520accounting.contacts.read%252520accounting.attachments%252520accounting.attachments.read%252520offline_access%252520payroll.employees%252520payroll.employees.read%2526state%253D108Sydney%2526code_challenge%253D3b5GLmW09QQB-C4Sq8ud0M0sEYpqFr5_KY20way8l1U%2526code_challenge_method%253DS256&dt=Login%20%7C%20Xero%20Accounting%20Software&sid=1615983898&sct=1&seg=0&en=page_view&_fv=1&_nsi=1&_ss=1' because it violates the following Content Security Policy directive: "default-src 'self' https://browsercheck.xero.com https://edge.xero.com https://js-agent.newrelic.com https://bam.nr-data.net https://telemetry.ext.platformdevelopment.xero.com https://api.mixpanel.com https://www.googletagmanager.com https://www.facebook.com https://connect.facebook.net https://p.adsymptotic.com https://*.fls.doubleclick.net https://*.linkedin.com https://www.google-analytics.com https://identity.xero.com https://login.xero.com https://go.xero.com https://static.xero.com 'unsafe-inline'". Note that 'connect-src' was not explicitly set, so 'default-src' is used as a fallback.
", source: https://www.googletagmanager.com/gtag/js?id=G-Q622B96ZEQ&l=dataLayer&cx=c (333)
[0317/232458.806:INFO:CONSOLE(333)] "Refused to connect to 'https://stats.g.doubleclick.net/g/collect?v=2&tid=G-Q622B96ZEQ&cid=1821054078.1615983899&gtm=2oe330&aip=1' because it violates the following Content Security Policy directive: "default-src 'self' https://browsercheck.xero.com https://edge.xero.com https://js-agent.newrelic.com https://bam.nr-data.net https://telemetry.ext.platformdevelopment.xero.com https://api.mixpanel.com https://www.googletagmanager.com https://www.facebook.com https://connect.facebook.net https://p.adsymptotic.com https://*.fls.doubleclick.net https://*.linkedin.com https://www.google-analytics.com https://identity.xero.com https://login.xero.com https://go.xero.com https://static.xero.com 'unsafe-inline'". Note that 'connect-src' was not explicitly set, so 'default-src' is used as a fallback.
", source: https://www.googletagmanager.com/gtag/js?id=G-Q622B96ZEQ&l=dataLayer&cx=c (333)
[0317/232458.819:INFO:CONSOLE(0)] "Refused to load the image 'https://www.google.com.au/ads/ga-audiences?v=1&t=sr&slf_rd=1&_r=4&tid=G-Q622B96ZEQ&cid=1821054078.1615983899&gtm=2oe330&aip=1&z=174504349' because it violates the following Content Security Policy directive: "img-src 'self' https://browsercheck.xero.com https://edge.xero.com https://js-agent.newrelic.com https://bam.nr-data.net https://telemetry.ext.platformdevelopment.xero.com https://api.mixpanel.com https://www.googletagmanager.com https://www.facebook.com https://connect.facebook.net https://p.adsymptotic.com https://*.fls.doubleclick.net https://*.linkedin.com https://www.google-analytics.com https://identity.xero.com https://login.xero.com https://go.xero.com https://static.xero.com".
", source: https://login.xero.com/identity/user/login?...

我验证了语言环境文件夹,它与我本地系统中的相同。它说拒绝连接,因为它违反了某些东西.. 那么当我第二次尝试时它不应该工作。所以我完全不知道这里发生了什么。谁能告诉我这里有什么问题吗?

求助!

这是非常基础的。我没有初始化 Cef。因为它第二次在没有它的情况下工作。当应用程序启动时,我确实在 App.xaml.cs 中初始化了它,现在它每次都能正常工作。虽然我仍然想知道它为什么工作(如果我第二次加载 window 而没有初始化 Cef)。

这是我添加的。

 if (!Cef.IsInitialized)
                {
                    try
                    {
                        //Perform dependency check to make sure all relevant resources are in our output directory.
                        Cef.Initialize(new CefSettings(), performDependencyCheck: true, browserProcessHandler: null);
                    }
                    catch(Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        ErrorLogger.LogError(ex.GetType().ToString(), ex, GetType().FullName, System.Reflection.MethodBase.GetCurrentMethod().Name);
                    }
                }

由于它在我的系统中运行良好而无需初始化 Cef,因此我认为这不是强制性的。不过好像很有必要。