chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.38k stars 467 forks source link

chrome: Disable "Restore pages" popup after incorrect shutdown #3767

Closed razor999920 closed 3 months ago

razor999920 commented 3 months ago

Issue

I have a WPF application using Cefsharp 126.2.70. The changes from the 126.2.70 changes the cefsettings runtime to chrome. The ChromeRuntime bootstrap opens a random chrome tab when the WPF window is loaded. This does not happen every time but it happens on every other try of opening the application. Below the what the tab looks like: cef

Reproduce

Expected Behavior

Versions

Code Example

App.xaml.cd ` private void Application_Startup(object sender, StartupEventArgs e) { var settings = new CefSettings() { // ChromeRuntime = false, LogFile = "Debug.log", LogSeverity = LogSeverity.Verbose, CachePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\Cache"), };

    // //Perform dependency check to make sure all relevant resources are in our output directory.
    // settings.CefCommandLineArgs.Add("disable-gpu", "1");
    // settings.CefCommandLineArgs.Add("disable-gpu-compositing", "1");
    // settings.CefCommandLineArgs.Add("disable-extensions", "1");
    // Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

    Cef.Initialize(settings);

    // Open Window
    MainWindow mainWindow = new MainWindow();
    mainWindow.Show();
}

`

MainWindow.xaml.cd ` public MainWindow() { InitializeComponent();

    Browser.LoadUrl("www.google.com");

} `

magreenblatt commented 3 months ago

Are you calling CefShutdown? Is your application crashing?

razor999920 commented 3 months ago

No I'm not calling CefShutdown, and the application is running as intended. When you run the application, it randomly opens a empty chromium tab along side the application. The tab serves no purpose.

I have also tested this on other machines, and get the same result.

magreenblatt commented 3 months ago

No I'm not calling CefShutdown

You need to call CefShutdown (or CefSharp equivalent) for proper shutdown. That is likely why you're getting the popup window with "Chromium didn't shut down correctly".

razor999920 commented 3 months ago

Sorry for the ignorance but why would I need to call CefShutdown? isn't its purpose to close the application? https://github.com/cefsharp/CefSharp/issues/2487#issuecomment-413501667

The issue i'm encountering happens during the application startup

magreenblatt commented 3 months ago

You can try the --hide-crash-restore-bubble command-line flag, or setting CefSettings.persist_session_cookies to false.

This is related to prefs::kRestoreOnStartup which is configured here in CEF. A value of SessionStartupPref::kPrefValueLast will cause ShouldRestoreLastSession to return true in SessionService::ShouldRestore.

magreenblatt commented 3 months ago

Sorry for the ignorance but why would I need to call CefShutdown? The issue i'm encountering happens during the application startup

This issue is likely occurring because your previous application run did not shut down CEF/Chromium properly. From your link it sounds like CefSharp may call CefShutdown for you. I suggest you explore why that might not be occurring in your case. For example, maybe your application is crashing during shutdown.

razor999920 commented 3 months ago

@magreenblatt Thank you so much! that worked. You are correct the issue was with the closing of the app and the command line flag helped.

SinyimZhi commented 2 months ago

@magreenblatt I encountered a similar problem In the cef_binary_128.4.9+g9840ad9+chromium-128.0.6613.120_windows64. My Win32 program needs to enable persist_session_cookies to save some tokens. Whether or not I add --hide-crash-restore-bubble to the command line flag, the program will pop up the page where it exited abnormally before. My application does call CefShutdown, but we cannot always expect the program have executed CefShutdown , such as killing processes from the task manager or the other processes. Now we can just disable persist_session_cookies to solve this problem, but I think we need a switch to individually control whether the infinite recovery function is enabled or not. Or our application can handle whenever to restore these sessions?