Search code examples
c#.netwpfcefsharp

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


Hi i have wpf desktop application. I am using cefsharp.wpf chromium browser to open web page. I added cefsharp from nuget pacakge manager (version 87.1.132). it does work very well in my system (Windows 10, 64 bit os).

But when i run my exe in client's environment (windows 2012 r2,64 bit os), strange thing happens, which is browser doesn't load only when i try first time. basically i have a button & on button click i do open one window which has cefsharp chromium browser in it. so when window opens first time browser doesn't load anything. now if i close window and open it again browser will redirect to my url . only first time browser doesnt load. after first time it does load everytime until i close exe and try again.

if i close exe and open it again and try to open that window, again browser will not load anything. then i close that window and try again browser will work perfectly.

What i am doing is very simple i have browser in xaml file in one window, and in cs file when window is loaded i am assigning one address to browser and that's it.

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

in xaml.cs on window loaded

browser.address = url; // i am using www.xero.com login url (which i dont think should matter as it does work second time).

can anybody tell me what's happening here ?

I have debug.log file for cefsharp which says:

[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?...

i verified locale folder it is same as it is in my local system. And it says refused to connect as it violates something.. then it shouldn't work when i try second time. So i am totally confused what's happening here. can anybody tell me whats wrong here ?.

Help !


Solution

  • This was very basic. I hadn't initialized Cef. As it was working without it second time. I did initialize it in App.xaml.cs when application is starting and now it does work fine everytime. Although i still wonder why it was working (if i load window second time without initializing Cef).

    Here's what i added.

     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);
                        }
                    }
    

    As it was working very well in my system without initializing Cef i thought it isn't compulsory to do that. But it seems that it is necessary.